相关方法
1. setSilentMode <boolean>
开关Silent 模式。如果设为Off,在位图输入、输出过程中发生的任何错误都会导致一
个错误信息对话框。如果设为On,在位图输入、输出过程中发生的任何错误都不会显示。
返回一个布尔值,表示调用本函数前的Silent 模式。
Silent 模式是3ds max 内部的一个状态,其他3ds max 插件也可以开关该模式。建议用
户如果使用本函数开关Silent 模式,将返回值保存,在执行完位图输入、输出操作后,将
它的状态恢复到原来的值。
2. silentMode()
返回一个布尔值,表示当前的Silent 模式。
3. selectSaveBitmap [ caption:<open_dialog_title_string> ]
显示一个3ds max 位图文件存储对话框,并返回一个字符串,表示完整的文件路径名。
如果用户按Cancel 退出对话框,返回值为undefined。
--获取物体的长宽高
--obj 想要获取尺寸的物体
fn getOjbSize obj=(
siz_x = ( abs obj.max.x ) + ( abs obj.min.x )
siz_y = ( abs obj.max.y ) + ( abs obj.min.y )
siz_z = ( abs obj.max.z ) + ( abs obj.min.z )
return [siz_x,siz_y,siz_z]
)
--查找没有UV的物体,然后自动加一个UV
len = 400
for eobj in geometry do
(
cls = getClassName eobj
if(cls=="可编辑网格" or cls=="Editable Mesh") then
(
nvt = getNumTVerts eobj
if(nvt!=undefined and nvt==0) then
(
select eobj
modPanel.addModToSelection (Uvwmap()) ui:on
if($.modifiers[#UVW_Mapping]!=undefined) then
(
$.modifiers[#UVW_Mapping].maptype = 4
eobj.modifiers[#UVW_Mapping].length = len
eobj.modifiers[#UVW_Mapping].width = len
eobj.modifiers[#UVW_Mapping].height = len
)else
(
$.modifiers[#UVW_Map].maptype = 4
eobj.modifiers[#UVW_Map].length = len
eobj.modifiers[#UVW_Map].width = len
eobj.modifiers[#UVW_Map].height = len
)
)
)
)
-----------
mappaths.getfullfilepath "57399f0a495b9b4f637a3b2e60bb7df5.jpg" --返回完整的文件路径 "X:\texture\57399f0a495b9b4f637a3b2e60bb7df5.jpg" 如果没有找到相应的贴图,则返回"",可以以此来判断这个贴图是否存在,如果不存在则提示
mBitmaps =getClassInstances BitmapTexture --返回场景中所有的BitmapTexture的数据.使用这个也可找到场景中任何类型的全部信息
mapfiles = mBitmaps
for m in mapfiles do(
if (isproperty m #filename) then(
if m.filename !="" then(
if mapPaths.getfullfilepath m.filename!="" do print m.filename
)
)
)
mapPaths.getfullfilepath m.filename!="" --这个可以判断这个路径的文件是否真的存在
doesFileExist m.filename --这个也可以判断这个路径的文件是否真的存在
注:可以用这个方法查找丢失贴图的物体
-------------------------------------------------------------------------------------------------------
GetclassName meditMaterials[3] --返回字符串 "VRayMtl"
classof meditMaterials[3] --返回的是类型名 VRayMtl
meditMaterials[3].classID[1] --
2. <MAXWrapperobject>.classID
<maxclass>.classID
.classID 属性返回MAXWrapper 类或对象在3ds max 内部的类码,返回值为一个包含两
个数字的数组:PartA 和PartB。如:
Box.classID --返回#(16,0)
b=Box()
b.classID --返回#(16,0)
-------------------------------------------------------------------------------------------------------
----去除重复元素
fn RemoveTheSame List =
(
try
(
local Alist=#()
if List.count>0 then
(
for i=1 to List.count do
(
local t = 1
if Alist.count==0 then (append Alist List[i])
--判断Alist是否有这个List[i]相同的元素
else if Alist.count>0 then
(
for j=1 to Alist.count do
(
if List[i]==Alist[j] then( t=0;exit) --如果有相同元素则将t设为0,并退出这次循环
)
--如果将List[i]和Alist里的每一个元素对比完了,并没有发现有相同元素,即t还是等于1,则将这个List[i]添加进Alist数组中
if t==1 do append Alist List[i]
)
)
)
--遍历完了List里的元素后返回Alist
if (Alist.count>0) then (sort Alist;return Alist)
)
catch()
)
---------------------------------------
local mBitmaps = getClassInstances BitmapTexture -- gets all bitmapTextures in the scene 返回场景里所有的贴图
isProperty aes[2] #filename 跟上面的结合使用,
8. refs.dependents <MAXWrapper_object>
返回一个Name 类数组,表示依赖于指定MAXWrapper 对象的所有MAXWrapper 对象
类名。指定的参数<MAXWrapper_object>可以为任何MAXWrapper 对象,比如Node(场景
对象)、Modifier(修改器)、Material(材质)、Controller(控制器)等。如:
6. getClassName <MAXWrapper>
将MAXWrapper 类名作为一个字符串返回。
findString d "changok" --在字符串中d中查找字符串changok,没找到则返回undefined
4. findString <string> <search_string>
在字符串<string>里查找字符串<search_string>,如果有找到,则返回第一个找到字符
的序号,否则返回值undefined。例如:
findString "Thanks for all the fish! " "all" --返回12
GetDirectories (d+"/*") --查找d路径下的所有子路径--获取文件夹路径
GetFiles path --获取场景文件
配合getSavePath()--选择文件夹 使用,可以获取些文件夹下所有的文件名
-----------
deleteItem dir_array (findItem dir_array d) --findItem dir_array d 从数组里查找某个元素,找到则返回其序号 --deleteItem <array> <number> 从数组中删除指定索引的元素 配合findItem使用
/*
--获取指定文件夹的max文件
--这个root可以用getSavePath()来获取
fn getmaxfile root=
(
--获取此文件夹下的max文件
getFiles (root+"\*.max") --返回的是一个数组
)
*/
--将记录或结果写入文件
fn SetFileStrList sfile str_array =
(
in_text = CreateFile sfile
for d in str_array do
(
format "%\n" d to:in_text
)
--flush in_text
close in_text
)
--usedMaps() 返回一个由当前场景所有使用过的贴图文件名组成的数组
------------将特殊字符串的材质球名改名------------------------
try(
mats = Scenematerials
i=1
for mat in mats do
(
ones = filterstring mat.name " -,.':;[]{}!@#$%^&*()"
if ones.count==1 then mat.name = ones[1]
else if ones.count>1 then mat.name= ones[1]+"_h"+ i as string
i+=1
)
)
catch()
----------查找材质球包括某个名字,然后改名--------------------------
mats = SceneMaterials
--matchPattern s pattern : "text?"
i=0
for mat in mats do (
if matchPattern mat.name pattern:"YF_屏幕*" do(
oldmtlname = mat.name
mat.name = "YF_dengdai"+"_a"+i as string
newmtlname= mat.name
print(oldmtlname+"--改名成功---"+newmtlname )
i+=1
)
)
-------------------20190228--------------------------
--Editable_poly 看点的数量 $.numverts
--Editable_mesh 看点的数量 $.faces.count
for a in $* where ((classof a == Editable_poly and a.numverts == 0) or (classof a == Editable_mesh and a.faces.count==0)) do (
delete a
print(a.name)
)
-------20190220
mfn = maxfilename --获取当前文件的文件名 "1011010.max"
sceneName = maxFilePath + maxFileName --获取文件路径与文件名
name2 =getFileNameFile mfn --去除后缀名.max后的名字 1011010
---------2090218
SP4relinkmapDlg = newRolloutFloater "指定贴图" 330 291
方法二:还可以用函数newRolloutFloater()来创建无模式的浮动窗口。这种窗口显示在
Windows 桌面上,类似于3ds max 系统的Material Editor 和Selection 浮动窗口。用户可以
用鼠标在这些窗口和3ds max 主界面之间随意切换。
//20190216
//操作材质篇
$.material = standard() --给选中物体创建一个标准材质
activeMeditSlot --获取激活(在材质编辑器中选择的材质)材质球的index
mtl = meditMaterials[activeMeditSlot] --获取激活(在材质编辑器中选择的材质)材质球
--修改材质贴图通道,
$.material.diffusemap = Bitmaptexture() --先在漫反射里指定一个MAP的通道
$.material.diffsusemap.filemap = "贴图路径"
showTextureMap $.material $.material.diffusemap On --显示某张贴图在场景视图
//如果物体是线条,可以修改段数
for a in selection do a.steps=1 --a.steps=1 不可以有空格
//旋转物体
for a in selection do rotate (angleaxis 45 [x,y,z]) --45可以换成(random 20 120),轴向也是可以换成随机轴向即
for a in selection do rotate a(angleaxis (random 20 120) [(random -1 1),(random -1 1),(random -1 1)])
for a in selection do rotate a(angleaxis (random 20 120) [(random -1 1),(random -1 1),(random -1 1)]) ---1为某轴的反方向,1为某轴的正方向
--//移动物体
for a in selection do move a[x,y,z] --将物体的某体移动到x,y,z
--还可以用随便数,比如
for a in selection do move a[(ramdom -100 100),((ramdom -100 100),(ramdom -100 100))]
--表示随机位置还可以这样写
for a in selection do move a(random[-100,-100,-100] [100,100,100])
--上面是使用move方法做的移动
--使用$.pos还可以改变物体的位置
for a in selection do a.pos=[x,y,z]
--随机位置
for a in selection do a.pos=[[(ramdom -100 100),((ramdom -100 100),(ramdom -100 100))]]
--应该还可以这样写
for a in selection do a.pos=(random[-100,-100,-100] [100,100,100])
--将选择的物体定义为一个数组
a = selection as array
--a数组的个数
a.count
--for循环a做某事
for i=1 to a.count do something
--定义选择集(枚举)
y = #(red,green,blue,yellow,orange,brown,white) --MAX默认9种颜色
--选择物体赋予材质,并将其颜色设置上y选择集中的成员
for a in selection do a.material=standard diffuse:y[random 1 7] --漫反射颜色为随机y里面的7种颜色
--指确切颜色
for a in selection do a.material=standard diffuse:y[7]
--随机移动偏移关键帧
i=0
--for a in selection do movekeys a(i+=2偏移量)
for a in selection do movekeys a(random 1 7) --将选择物体的关键帧偏移1到7的随机值
--变量名的合法与非法
--合法变量有
r123
food
_123
_123def
i_have_a_hourse
地球
"good" as name
marble()
--非法变量名有
3poo
yes?
a big hourse
[dollar_7]
--选择包含此字符的物体
select$*灯泡*
--添加修改器
ffd=ffdbox()--新建个修改器变量,后面可以直接加这个
for a in selection do addmodifier a(flex flex:1) --flex为修改器名(这个是柔体-动画时有颤抖效果) flex:1 --修改这个修改器的flex属性,用属性名:数值的形式修改修改器里的内容
for a in selection do a.modifiers[#flex].flex=2
--添加切片修改器
for a in selection do addmodifier a(SliceModifier())
-- showproperties $ 显示当前选中物体的所有属性
--showclass"chamferbox.*" 显示一类物体的所有属性(这里是切角
长方体)
--生成一个彩色的方体
(step = 15
for r=0 to 255 by step do
for g=0 to 255 by step do
for b=0 to 255 by step do
box width:step height:step length:step pos:[r,g,b] wirecolor:[r,g,b]
)
--数组
--数组的表示方法,ms中的数组是一种稀疏数组,每个元素的类型可以不同,数组中元素的个数不限 --数组的索引从1开始,而不是其他语言的从0开始,数组的长度属性是count
--给数组中添加元素
append myArr = #()
append myArr "richard stevens tcp/ip illustrated" -- 给数组中添加元素
--随机颜色
x= 0 --定义变量
for a in selection do movekeys a(x+=1) --偏移关键帧
for a in selection do a.steps=6 --设置文字的段数
y = #(red,green,blue,yellow,orange,brown,white) --定义选择集
for a in selection do a.material=standard diffuse:y[random 1 7] --选择物体随便指定材质颜色
for a in selection do a.material=standard diffuse:y[7] --指定选中物体使用选择集里的哪个颜色
for a in selection do addmodifier a (flex flex:1) --加柔体修改器
for a in selection do a.modifiers[#Flex].Flex =2 --修改修改器里的参数
--------------20180410----------------
--------------批量删除修改器---特别是针对空间修改器,这些手动塌陷不了的修改器-
fn HDeleteModifier=(
for a in $ do( Hddf a)
)
-------------批量删除修改器--------
fn Hddf obj = (
a = obj.modifiers --返回物体的所有修改器数组
if a.count!=0 do (for i=1 to a.count do (deletemodifier obj 1)) --如果修改器数组不等于0,说明物体有修改器,有,则遍历删除
)
-------------------end-------------------
PathName 路径名
<path_name>::=$<path>|$
$dummy/head/neck --选择dummy里head下面的neck名字的对象
$dummy/* --选择dummy里的所有子对象
$dummy* --指定了层级结构中任何名字以dummy形状的对象
$dummy? --表示那此后名字以dummy开头,且后面只有一个字符的对象
--指定父对象级别
$dummy/*/* --指定dummy父对象的所有子对象的子对象
$dummy/.../box* --指定dummy父对象下任意级别里的名字以box形状的所以对象 还可以写成$dummy ... box*
max hide $*foot* --隐藏所有名字中包含字符foot的对象
$*box*.position +=[10,10,0] --一次设置所有匹配对象的属性
如果名字里有其它字符,为防止不小心使用了特殊字符,可以加上单引号''将里面的字符引起来。并且将特殊字符加\字号
a = $*feet*[i] --获取对象集feet里的第i个对象
--检测那些.scale属性是不是单件矢量的对象
for obj in $dummy...*
where obj.scale != [1,1,1]
do format "% has non-identity scale:&\n" obj.name obj.scale
--将对象foo的.pivot属性设为对象集box的右上角
$foo.pivot = $Box*.max
in $dummy
(sphere name:"ear1" pos:[10,10,10,]
sphere name:"ear2" pos:[-10,10,10]
scale $foo/* [1,1,2]
)
---------------------
Ojbect(对象集)
构造函数
objects 所有场景对象
geometry 指定类型的3ds max对象
lights
cameras
helpers
shapes
systems
spacewarps
selection 当前选择对象集合
属性
1 <Ojbectset>.center --返回对象集中所有对象的绑定框的中心
2 <Ojbectset>.max --对象集绑定框的右上角
3 <Ojbectset>.min --左下角
4 <Ojbectset>.count --对象数目
5 操作符
<Ojbectset>[<integer>] 存取集合里指定序号的元素
<Ojbectset>as array 将对象集合转化为一个数组
相关方法
1 clearSelection() --清除当前场景对象选择集
2 deselect<PathName> 将指定对象从当前选择集里去掉
deselect $Box* --将所有名字以box开头的对象从当前选择集里去掉
3 select<PathName> --先解除所有当前选择集,然后选择指定的对象
4 selectMore<PathName> --将指定对象添加进当前选择集中
5 getcurrentSelection()
-------------移动关键帧----------
-------20180403-17:57--------
fn hmovekyes it=
(
i=0
for a in $ do movekeys a(i+=it)
)
----------------
--动画制作visibility
fn visibilityoff tStart tEnd=(
local sStart2=tStart-1
local stEnd2=tEnd-1
fn visibilityon tStart tEnd=(
local sStart2=tStart-1
local stEnd2=tEnd+1
for obj in $ do
(if $.count>0 then(animate on
(
at time tEnd2 obj.visibility =off
at time tStart2 obj.visibility =off
at time tEnd obj.visibility =on
at time tStart obj.visibility =on
)
)
else messagebox"请选择物体")
)
)
--------------------------------------------------------
---------------------方法区,所以单独的方法可以写在这里-----------------------
--------------20180403----------------
---------指定随机生指定数量的box
fn randombox count=
(
for i=1 to count do
(
box width:(random 20 50) length:(random 20 50) position:[random 20 200,random 20 200,random 20 300]
)
)
--------
-------------依据名字选择物体----------------
fn AddArrayByName _name=(
d_list=#()
for obj in $* where((findstring obj.name _name )!= undefined ) do (append d_list obj)
return d_list
)
----------------------A2B----------------------
--------------------Begin-----------
macroScript AMove2B category:"HYQ Tools" buttonText:"AMove2B" tooltip:"AMove2B"
(
rollout AMove2B "AMoveB" width:162 height:400
(
label lbl1 "A" pos:[29,28] width:33 height:14
label lbl2 "B" pos:[101,28] width:33 height:14
editText edt1 "" pos:[16,51] width:55 height:18
editText edt2 "" pos:[88,51] width:55 height:18
editText edt3 "" pos:[16,84] width:55 height:18
editText edt4 "" pos:[88,84] width:55 height:18
editText edt5 "" pos:[16,118] width:55 height:18
editText edt6 "" pos:[88,118] width:55 height:18
editText edt7 "" pos:[16,153] width:55 height:18
editText edt8 "" pos:[88,153] width:55 height:18
editText edt9 "" pos:[16,190] width:55 height:18
editText edt10 "" pos:[88,191] width:55 height:18
editText edt11 "" pos:[16,227] width:55 height:18
editText edt12 "" pos:[88,227] width:55 height:18
button btn1 "AMovetoB" pos:[30,258] width:102 height:25
groupBox grp1 " Amove2B" pos:[8,11] width:146 height:400
------------------------------------------
---------------这个有点问题,不多个一起处理--------------
on btn1 pressed do
(
-------------定义变量并赋值------------
/*
edt1_lis=AddArrayByName edt1.text --可能需要加上 if edt1!=unsupplied do --20180403-17:06
edt2_lis=AddArrayByName edt2.text
edt3_lis=AddArrayByName edt3.text
edt4_lis=AddArrayByName edt4.text
edt5_lis=AddArrayByName edt5.text
edt6_lis=AddArrayByName edt6.text
edt7_lis=AddArrayByName edt7.text
edt8_lis=AddArrayByName edt8.text
edt9_lis=AddArrayByName edt9.text
edt10_lis=AddArrayByName edt10.text
edt11_lis=AddArrayByName edt11.text
edt12_lis=AddArrayByName edt12.text
*/
------------------------------
if edt1!=unsupplied do (edt1_lis=AddArrayByName edt1.text) --可能需要加上 if edt1!=unsupplied do
if edt2!=unsupplied do edt2_lis=AddArrayByName edt2.text
if edt3!=unsupplied do edt3_lis=AddArrayByName edt3.text
if edt4!=unsupplied do edt4_lis=AddArrayByName edt4.text
if edt5!=unsupplied do edt5_lis=AddArrayByName edt5.text
if edt6!=unsupplied do edt6_lis=AddArrayByName edt6.text
if edt7!=unsupplied do edt7_lis=AddArrayByName edt7.text
if edt8!=unsupplied do edt8_lis=AddArrayByName edt8.text
if edt9!=unsupplied do edt9_lis=AddArrayByName edt9.text
if edt10!=unsupplied do edt10_lis=AddArrayByName edt10.text
if edt11!=unsupplied do edt11_lis=AddArrayByName edt11.text
if edt12!=unsupplied do edt12_lis=AddArrayByName edt12.text
--------调用方法---移动物体-----------------
/*
if idt1_lis !=undefined and idt2_lis !=undefined do A2B edt1_lis edt2_lis --edt1_lis 移动到 edt2_lis
if idt3_lis !=undefined and idt4_lis !=undefined do A2B edt3_lis edt4_lis
if idt5_lis !=undefined and idt6_lis !=undefined do A2B edt5_lis edt6_lis
if idt7_lis !=undefined and idt8_lis !=undefined do A2B edt7_lis edt8_lis
if idt9_lis !=undefined and idt10_lis !=undefined do A2B edt9_lis edt10_lis
if idt11_lis !=undefined and idt12_lis !=undefined do A2B edt11_lis edt12_lis
*/
A2B edt1_lis edt2_lis
A2B edt3_lis edt4_lis
A2B edt5_lis edt6_lis
A2B edt7_lis edt8_lis
A2B edt9_lis edt10_lis
A2B edt11_lis edt12_lis
----------定义数组的元素数量-----------
/*
idt1_count=idt1_lis.count
idt2_count=idt2_lis.count
idt3_count=idt3_lis.count
idt4_count=idt4_lis.count
idt5_count=idt5_lis.count
idt6_count=idt6_lis.count
idt7_count=idt7_lis.count
idt8_count=idt8_lis.count
idt9_count=idt9_lis.count
idt10_count=idt10_lis.count
idt11_count=idt11_lis.count
idt12_count=idt12_lis.count
*/
--if (idt1_lis_count) >1 and (idt2_lis_count) >1 do A2B edt1_lis edt2_lis --edt1_lis 移动到 edt2_lis
--if (idt3_lis_count) >1 and (idt4_lis_count) >1 do A2B edt3_lis edt4_lis
--if (idt5_lis_count) >1 and (idt6_lis_count) >1 do A2B edt5_lis edt6_lis
--if (idt7_lis_count) >1 and (idt8_lis_count) >1 do A2B edt7_lis edt8_lis
--if (idt9_lis_count) >1 and (idt10_lis_count) >1 do A2B edt9_lis edt10_lis
--if (idt11_lis_count)>1 and (idt12_lis_count) >1 do A2B edt11_lis edt12_lis
)
)
createDialog AMove2B 180 300 --显示这个窗口放在rollout 函数块之后 名字要与rollout 一致 这里的数定决定框框的大小
)
---------------------End------------------------------------
------------函数体---------------
---------begin------------
------------提供名字--------选择所有包括这个名字的物体
fn AddArrayByName _name=(
d_list=#()
for obj in $* where((findstring obj.name _name )!= undefined ) do (append d_list obj)
return d_list
)
-----------
------A对象移动在B对象所在位置-------------
--开始
--传两个Array 数组集合
fn A2B a_list b_list = (
a_l_count = a_list.count --存元素个数
b_l_count = b_list.count --存元素个数
--local a_list = if a_l_count>1 then a_list as array --如果大于1则将它作为数组存起来
--local b_list = if b_l_count>1 then b_list as array --如果大于1则将它作为数组存起来
if a_l_count>1 and b_l_count>1 do
(icount = if a_l_count>b_l_count then b_l_count else a_l_count --将ab两个数组中较小的一个存起来作为环时用
for i=1 to icount do a_list[i].pos=b_list[i].pos --遍历对象进行位置移动,只进行元素较小一方的元素数量次数)
))--结束
--------标准文件打开、存储对话框
1.getOpenFileName [caption:<tile>]\
[filename:<seed_filename_string>]
[types:<description1>]
getSaveFileName [caption:<tile>]\
[filename:<seed_filename_string>]
[types:<description1>]
--------------
--
--getsavepath() --打开一个对话框让客户指定保存文件的路径
files = getsavepath()
--获取指定文件的路径部分
--------文件名提取--------------
abc = getfilenamepath "L:\\2018\\rnf\\20180328\\zzwj\\提交文件\\model\\侧吸YT10A-C3-C.max" --要指定完整路径名
--"L:\2018\rnf\20180328\zzwj\提交文件\model\"
--获取文件的名称名分
getfilenameFile "L:\\2018\\rnf\\20180328\\zzwj\\提交文件\\model\\侧吸YT10A-C3-C.max"
--"侧吸YT10A-C3-C"
--返回完整路径的文件名及扩展名
filenamefrompath "L:\\2018\\rnf\\20180328\\zzwj\\提交文件\\model\\侧吸YT10A-C3-C.max"
--"侧吸YT10A-C3-C.max"
--返回指定完整文件名<filename_String>的扩展名部分
getFilenameType "L:\\2018\\rnf\\20180328\\zzwj\\提交文件\\model\\侧吸YT10A-C3-C.max"
--".max"
--如果指定文件在磁盘中存在,返回True,否则返回Flase
doesFileExist "L:\\2018\\rnf\\20180328\\zzwj\\提交文件\\model\\侧吸YT10A-C3-C.max"
--------------------外部文件方法--------------20180408-----------------
getFiles<wild_card_filename_string>
saveMaxFile "L:\test1\顶吸YT10A-H5.max" saveAsVersion:2012--
filepath = getsavepath()
files = getfiles (filepath + "*.max")
--files = getfiles "L:\\test1\\*.max "
for f in files do (loadmaxfile f; SaveMaxFile f savemaxversion:2012)
----------max保存成低版本------version---SaveAsVersion:2012--------------
filespath = getsavepath() --打开对话框选择文件
hz = "*.max" --后缀名
patha = ((getDirectories filespath)[1])+hz --方便接下来getfiels使用的路径
files = getfiles patha --打开这个路径里的所有文件,返回一个数组储存起来
for f in files do (loadmaxfile f;SaveMaxFile f saveasversion:2012)
--quitMax #noPrompt ---退出MAX,没提示
maxversion()----返回MAX的版本
--------------- getsavepath()------------
getsavepath()
"L:\test1" --返回值
-----------getdirectories(getsavepath())-----------
getdirectories(getsavepath())
#("L:\test1\")
------------高版本改低版本改良----------------
-------------------201804090038更新--------------
--在所选择的文件夹下新建一个名为converhyq的文件夹,将外面的MAX打开后保存为一个低版本的max到这个文件夹中
filespath = getsavepath() --打开文件夹
makedir (filespath+"\converhyq") --在上面的新路径下创建文件夹
--返回打开对话框中指定文件夹下所有的MAX文件
files = getfiles (filespath + "\*.max")
--循环遍历files里的文件
resetmaxfile() #noprompt--重置MAX
--for f in files do (print f;loadmaxfile f;savemaxfile (filespath+"\converhyq"+"\\"+(getfilenamefile f) + (getfilenametype f)) saveasversion:2012)
for f in files do (delete $* ;print f;megermaxfile f;savemaxfile (filespath+"\converhyq"+"\\"+(getfilenamefile f) + (getfilenametype f)) saveasversion:2012)
------------------20180413----------
-------------位置随机------------
fn randpos rang_pos = (
for obj in $ do move obj(random[-rang_pos,-rang_pos,-rang_pos] [rang_pos,rang_pos,rang_pos])
)
----------移动关键帧----------
fn hmoveKeys step= (
for a in $ do movekeys a(step)
)
-------------缩放关键帧---------------
fn hscaleTime Tstart Tend step = (
for a in $ do scaletime a Tstart Tend step
)
---------------------计算关键帧数量--------------------
fn keyscount =
(
ke = for a in $ where (a.position.controller.keys !=undefined) collect a.position.controller.keys
i= ke.count
jj=0
for i = 1 to i do
(jj+=ke[i].count
)
return jj
)
-------------------------
------以平面的节点建立方块---------
fn creatBoxss =
(c = $plane001 --选择变形面
for i=0 to c.mesh.numfaces/2-1 do --循环建立方块物体,并且附加到变形面上
(
s = box()--建立一个方块物体并将此物体指定给s
actrl = attachment() --建立一个附加动画控制器,并指定给actrl
s.position.controller = actrl --为虚拟物体s施加这个动画器actrl
actrl.node = c --为动画器actrl拾取对象为最下面的大面plane001
---以下程序设置时间、设置位置和设置面
addnewkey actrl 0f
theAkey = AttachCtrl.getKey actrl 1
theAkey.face = i*2
theAkey.coord = [1,0]
)
selectionSets["boxss"] = $box* --建立选择集合
)
-------------------------------------------
---------------------------------------
--塌陷位置动画,没有塌陷旋转和缩放动画
fn colAnimate =
(
star_t = 0 --开始时间
end_t = 200 --结束时间
sample_t = 5 --时间间隔
senum = selectionsets[#boxss].count --选择集里的物体数量
for i in 1 to senum do
(
obj_pos = #() --
for ii = star_t to end_t by sample_t do
(
at time ii
append obj_pos selectionsets[#boxss][i].pos
)
selectionsets[#boxss][i].pos.controller = Position_XYZ()
obj_pos_list =1
animate on
(
for ii=star_t to end_t by sample_t do
(
at time ii(selectionsets[#boxss][i].pos = obj_pos[obj_pos_list])
obj_pos_list +=1
)
)
))
---------------20180504---------------------------------------
selectionsets["集合名"] = $box* --selectionsets["集合名"] = $ --建立集合
selectionsets[#集合名] --选择集合
-----------------------------------20180516----------------------
1. <Bitmaptexture>.reload()
重新装载位图文件。
2. <Bitmaptexture>.viewImage()
查看源图像。
相关方法
1. enumerateFiles [ <MAXWrapper_obj> ] <function> [ <arg> ] \
[ #inactive ] [ #videoPost ] [ #render ] [ #missing ] \
[ #localOnly ]
让用户对场景里或指定单个对象里用到的所有位图文件进行循环,也可以对位图文件
进行过滤。
2. freeSceneBitmaps()
第2 部分 用MAXScript 操作场景对象
568
释放所有由位图缓存占用的内存。如果内存被许多位图文件分割成许多碎片,而用户
又想将当前活动的位图文件重载,本方法非常有用。
3. usedMaps()
返回一个由当前场景所有使用过的贴图文件名组成的数组。
---------------------20180507清理空贴图通道------hyq添加-------------------------------------
fn ClearNullMap=
(macros.run "Medit Tools" "condense_medit_slots" --清理一遍材质编辑器里的材质球,将场景没有用到的材质球清理掉
scenemats = sceneMaterials --将场景所有用到的材质存起来
--第一次遍历场景,收集所需要贴图
--------------已成功-----------
for mat in scenemats do
(
--打印材质名
--print mat.name
--判决材质类型 VRayMtl(VR材质球) OR Standardmaterial(标准材质球)
--收集texmap_diffuse(漫反射)
---------------------------------------------------------当为VR材质时-------------------------------------------------------
if classof mat == VRayMtl then
(
--判断漫反射
if ((mat.texmap_diffuse!=undefined) and (classof mat.texmap_diffuse == Bitmaptexture) and (mat.texmap_diffuse.filename == "" or mat.texmap_diffuse.filename == undefined) )then mat.texmap_diffuse = undefined --默认贴图时
if ((mat.texmap_diffuse!=undefined) and (classof mat.texmap_diffuse == Falloff)) then ( if ((mat.texmap_diffuse.map1!=undefined) and (mat.texmap_diffuse.map1.filename =="" or mat.texmap_diffuse.map1.filename == undefined)) then (mat.texmap_diffuse.map1=undefined)) --为Falloff时
if ((mat.texmap_diffuse!=undefined) and (classof mat.texmap_diffuse == Falloff)) then ( if ((mat.texmap_diffuse.map2!=undefined) and (mat.texmap_diffuse.map2.filename =="" or mat.texmap_diffuse.map2.filename == undefined )) then (mat.texmap_diffuse.map2=undefined))
--判断反射
if ((mat.texmap_reflection!=undefined) and (classof mat.texmap_reflection == Bitmaptexture) and (mat.texmap_reflection.filename == "" or mat.texmap_reflection.filename ==undefined ) )then mat.texmap_reflection = undefined --默认贴图时
if ((mat.texmap_reflection!=undefined) and (classof mat.texmap_reflection == Falloff)) then ( if ((mat.texmap_reflection.map1!=undefined) and (mat.texmap_reflection.map1.filename =="" or mat.texmap_reflection.map1.filename ==undefined)) then (mat.texmap_reflection.map1=undefined)) --为Falloff时
if ((mat.texmap_reflection!=undefined) and (classof mat.texmap_reflection == Falloff)) then ( if ((mat.texmap_reflection.map2!=undefined) and (mat.texmap_reflection.map2.filename =="" or mat.texmap_reflection.map2.filename ==undefined)) then (mat.texmap_reflection.map2=undefined)) --为Falloff时
--判断折射
if ((mat.texmap_refraction!=undefined) and (classof mat.texmap_refraction == Bitmaptexture) and (mat.texmap_refraction.filename == "" or mat.texmap_refraction.filename == undefined ) )then mat.texmap_refraction = undefined --默认贴图时
if ((mat.texmap_refraction!=undefined) and (classof mat.texmap_refraction == Falloff)) then ( if ((mat.texmap_refraction.map1!=undefined) and (mat.texmap_refraction.map1.filename =="" or mat.texmap_refraction.map1.filename ==undefined )) then (mat.texmap_refraction.map1=undefined)) --为Falloff时
if ((mat.texmap_refraction!=undefined) and (classof mat.texmap_refraction == Falloff)) then ( if ((mat.texmap_refraction.map2!=undefined) and (mat.texmap_refraction.map2.filename =="" or mat.texmap_refraction.map2.filename ==undefined )) then (mat.texmap_refraction.map2=undefined)) --为Falloff时
--判断凹凸
if ((mat.texmap_bump!=undefined) and (classof mat.texmap_bump == Bitmaptexture) and (mat.texmap_bump.filename == "" or mat.texmap_bump.filename ==undefined ) )then mat.texmap_bump = undefined --默认贴图时
if ((mat.texmap_bump!=undefined) and (classof mat.texmap_bump == Falloff)) then ( if ((mat.texmap_bump.map1!=undefined) and (mat.texmap_bump.map1.filename =="" or mat.texmap_bump.map1.filename ==undefined )) then (mat.texmap_bump.map1=undefined)) --为Falloff时
if ((mat.texmap_bump!=undefined) and (classof mat.texmap_bump == Falloff)) then ( if ((mat.texmap_bump.map2!=undefined) and (mat.texmap_bump.map2.filename =="" or mat.texmap_bump.map2.filename == undefined )) then (mat.texmap_bump.map2=undefined)) --为Falloff时
)
------------------------------------------------------当为标准材质时--------------------------------------------------------------------
if classof mat == Standardmaterial then
(
--判断漫反射
if ((mat.diffuseMap!=undefined) and (classof mat.diffuseMap == Bitmaptexture) and (mat.diffuseMap.filename == "" or mat.diffuseMap.filename ==undefined ) )then mat.diffuseMap = undefined --默认贴图时
if ((mat.diffuseMap!=undefined) and (classof mat.diffuseMap == Falloff)) then ( if ((mat.diffuseMap.map1!=undefined) and (mat.diffuseMap.map1.filename =="" or mat.diffuseMap.map1.filename == undefined)) then (mat.diffuseMap.map1=undefined)) --为Falloff时
if ((mat.diffuseMap!=undefined) and (classof mat.diffuseMap == Falloff)) then ( if ((mat.diffuseMap.map2!=undefined) and (mat.diffuseMap.map2.filename =="" or mat.diffuseMap.map1.filename == undefined)) then (mat.diffuseMap.map2=undefined)) --为Falloff时
--判断反射
if ((mat.reflectionMap!=undefined) and (classof mat.reflectionMap == Bitmaptexture) and (mat.reflectionMap.filename == "" or mat.reflectionMap.filename == undefined) )then mat.reflectionMap = undefined --默认贴图时
if ((mat.reflectionMap!=undefined) and (classof mat.reflectionMap == Falloff)) then ( if ((mat.reflectionMap.map1!=undefined) and (mat.reflectionMap.map1.filename =="" or mat.reflectionMap.map1.filename==undefined)) then (mat.reflectionMap.map1=undefined)) --为Falloff时
if ((mat.reflectionMap!=undefined) and (classof mat.reflectionMap == Falloff)) then ( if ((mat.reflectionMap.map2!=undefined) and (mat.reflectionMap.map2.filename =="" or mat.reflectionMap.map2.filename ==undefined)) then (mat.reflectionMap.map2=undefined)) --为Falloff时
--判断折射
if ((mat.refractionMap!=undefined) and (classof mat.refractionMap == Bitmaptexture) and (mat.refractionMap.filename == "" or mat.refractionMap.filename == undefined) )then (mat.refractionMap = undefined) --默认贴图时
if ((mat.refractionMap!=undefined) and (classof mat.refractionMap == Falloff)) then ( if ((mat.refractionMap.map1!=undefined) and (mat.refractionMap.map1.filename =="" or mat.refractionMap.map1.filename==undefined)) then (mat.refractionMap.map1=undefined)) --为Falloff时
if ((mat.refractionMap!=undefined) and (classof mat.refractionMap == Falloff)) then ( if ((mat.refractionMap.map2!=undefined) and (mat.refractionMap.map2.filename =="" or mat.refractionMap.map2.filename ==undefined)) then (mat.refractionMap.map2=undefined)) --为Falloff时
--判断凹凸
if ((mat.bumpMap!=undefined) and (classof mat.bumpMap == Bitmaptexture) and (mat.bumpMap.filename == "" or mat.bumpMap.filename ==undefined ) )then mat.bumpMap = undefined --默认贴图时
if ((mat.bumpMap!=undefined) and (classof mat.bumpMap == Falloff)) then ( if ((mat.bumpMap.map1!=undefined) and (mat.bumpMap.map1.filename =="" or mat.bumpMap.map1.filename ==undefined)) then (mat.bumpMap.map1=undefined)) --为Falloff时
if ((mat.bumpMap!=undefined) and (classof mat.bumpMap == Falloff)) then ( if ((mat.bumpMap.map2!=undefined) and (mat.bumpMap.map2.filename =="" or mat.bumpMap.map2.filename==undefined)) then (mat.bumpMap.map2=undefined)) --为Falloff时
)
))
---------------------------------------------
---------------修改器--------------------
10.1 Modifier: MAXWrapper
可以用方法addModifier()或 modPanel.addModToSelection()创建Modifier 和Spacewarp
Modifier 类并将它们添加到Modifier 堆栈里,除非特别说明,单词Modifier 的意思包含这
两大类。
通过创建一个 Modifier 并将它添加到几个对象里,用户可以在对象间共享一个
Modifier。就像在3ds max 界面里,我们可以将一个Modifier 赋给一个对象集合。
有两种方法可以存取现有的 Modifier:
第一种方法:作为一个属性,格式如<Node>.。当用户存取一个场景对象的一个属性,
如.name 或.position 时,MAXScript 也会将Modifier 视为对象的一个属性,如:
$Box1.heightsegs --获取创建参数
$Box1.twist --获取twist Modifier
$Box1.twist.angle --twist 角度
如果在 Modifier 的名称里有空格,可以用连字符“-”代替。如:
$Box1.uvw_map --获取UVW Map Modifier
这种方法比较简单,但经常存在下面的情况:几个Modifier 有着相同的名称,或Modifier
的名称与创建参数同名。如果仍然使用这种方法,系统总是返回第一个Modifier。这时可
以用第二种方法。
另一种方法是:使用数组机制存取现有的 Modifier。先获取一个Modifier 数组,然后
用序号对Modifier 进行索引。如:
$Box1.Modifiers --获取Modifier 数组
$Box1.Modifiers[3] --获取第三个Modifier
$Box1.Modifiers[#twist] --获取名称为twist 的Modifier
$Box1.Modifiers["ffd 4x4x4"] --获取FFD Modifier
从上面例子可以看出,我们既可以用Name 值,也可以用字符串作为Modifier 的名称
来引用Modifier,这一点是用第一种方法做不到的。
Modifier 在数组里的排序可以在Modify 面板的Modify stack 里看到,排序从1 开始。
Modifier 类和SpacewarpModifier 类是直接由MAXWrapper 类派生而来,并继承了该类
的属性和方法,这些属性和方法参见7.1 节“MAXWrapper 的通用属性和方法”。
第 10 章 Modifier(对象空间修改器)和
Spacewarp(世界空间修改器)
第10 章 Modifier(对象空间修改器)和Spacewarp(世界空间修改器)
423
10.2 Modifier 通用属性和方法
属性
所有的 Modifier 都有下面的属性:
1. <Modifier>.name: string
存取Modifier 的名称。
2. <Modifier>.enabled: Boolean
用来控制指定Modifier 的Enabled/Disabled 状态,可读/写属性,如:
$foo.Modifiers[2].enabled = False --关闭第二个Modifier
3. <Modifier>.enabledInViews : Boolean
用来控制指定Modifier 在视窗和渲染时是否显示。
相关方法
一个场景对象的 Modifier 堆栈可以用下面的方法进行操作:
1. validModifier(<Node> | <objectset>)<Modifier>
测试指定的Modifier 是否可以被添加到指定对象或对象集合,如果可以,返回True,
否则返回False。
2. addModifier <Node> <Modifier> [before:index] mapped
向指定对象添加指定Modifier 的实例(instance)。可选参数before:用来指定插入到
Modifier 堆栈指定的Modifier 之前的对象(从堆栈顶部开始计数)。如果指定对象当前正被
选择并在Modify 面板的某一子对象级打开,添加的Modifier 会被应用到子对象集合上。用
户可以用3ds max 系统变量subObjectLevel 来测试、设置当前的子对象级,如:
max modify mode --打开Modify 面板
select $Box01 --在Modify 面板下选择Box01 对象
subObjectLevel = 3 --将子对象级设为Face
addModifier $Box01(ffd_2x2x2()) --给Face 添加FFD Modifier
如果参数before:指定的位置为无效位置,该Modifier 会被放到离指定位置最近的有效
位置。比如:如果用户试图将一个SpacewarpModifier 类对象放到Modifier 类对象的下面,
系统会将SpacewarpModifier 类对象放在所有其他SpacewarpModifier 类对象的下面,但是
在所有Modifier 类对象的上面。
如果参数<Node>为一个对象集合,该集合里每一个对象都会放置一个指定Modifier 的
实例(instance)。如果要像在3ds max 界面里一样将一个Modifier 施加给一个对象集合,
可以使用函数modPanel.addModToSelection()。
函数 addModifier()的一个缺点是:它有时不能正确地将Modifier 赋给子对象集合,建
议用户在这种情况下使用函数modPanel.addModToSelection()。
3. deleteModifier <Node> <Modifier_or_index>
从Modifier 堆栈里删除指定Modifier。
第2 部分 用MAXScript 操作场景对象
424
4. collapseStack <Node> mapped
塌陷Modifier 堆栈,得到与指定对象相对应的可编辑的基对象,如Editable Mesh、
Editable Spline、NURBS Surface 等。如果当调用本函数时Modifier 堆栈里还没有Modifier,
不会执行任何操作。如果用户想强制将对象的堆栈塌陷或转换成某一指定类,应该使用转
换函数,如convertToMesh()、convertToSplineShape()等。
5. getModContextTM <Node> <Modifier>
返回一个Matrix3 值,表示指定Modifier 子对象gizmo 使用的转换矩阵。
6. getModContextBBoxMin <Node> <Modifier>
getModContextBBoxMax <Node> <Modifier>
返回Point3 值,表示指定Modifier 绑定框的坐标最小点和最大点,坐标系为World 坐
标系
---------------20150524在视图里显示材质贴图------------------------------------------------------
meditMaterials[9].showInViewport =true
------------------------DOCollect------------不收集---------20180525-----
3.3.4 DontCollect
DontCollect 类用于For 循环中标明哪些值不被收集到数组中,DontCollect 类仅有一个
同名实例:DontCollect。
例如:
--收集所有半径小于5 的Sphere 类对象
little_spheres =
for i in $* collect
if classOf i == sphere and i.radius < 5 then i else DontCollect
-----------------------zlt + x see-throught xray 物体透视切换---------------------------------------------
for a in $ do a.xray = off --(关闭半透明显示视) on打开透视
--------------------------------------------------------------------------------------
--isOpenGroupHead $ 是组头
--isOpenGroupMember $ 是组成员
--setGroupOpen $ false 关闭或打开组
--superclassof $ 判断类型
--exportFile pathnames #noprompt 导出文件
--exportFile (newPath+@"\"+fileName+".fbx") #noPrompt selectedOnly:true using:FBXEXP --导出选择物体
--file="g:\\subdir1\\subdir2\\myImage.jpg"
--filenameFromPath file --返回: "myImage.jpg"
--getFilenamePath file --返回: "g:\subdir1\subdir2\"
--getFilenameFile file --返回: "myImage"
--getFilenameType file --返回: ".jpg"
--select $obj --让某个对象处理选择状态
--MD5贴图
for d in text_dir_array do
(
filename = d + mapfn
-- messagebox filename title:("1") beep:off
if ((doesfileexist filename) and (mapfn !=" ")) then
(
--5 找到了,进行MD5码转换,返回MD5码文件名
f = getThisScriptFilename()
p = getFilenamePath f
cmd =("\""+p + "md5.exe" +"\""+" "+filename)
-- print cmd
--sleep(1)
-- messagebox cmd
HiddenDOSCommand cmd
md5fn = ""
-- --sleep(2)
in_text = openfile "d:/md5.txt"
if not eof in_text do
(
md5fn = readLine in_text
)
close in_text
--if md5fn == "" then
rmapfile = md5fn + ext
-- messagebox rmapfile title:("1") beep:off
toLower rmapfile
copyFile filename (g_texcopy + "\\" + rmapfile)
append md5files rmapfile
append md5files mapfn
bfind = true
exit
)
)