首页 > 技术文章 > 我的MAXSCRIPT笔记

timeObjserver 2018-01-31 11:13 原文

  1 1 getnodebyname "circle01"
  2 2 for o in objects do
  3       if o.name == "circle01" then
  4 3 select $Box* – select any objects with the name box at the beginning of them.
  5 4 move, scale rotate
  6     move obj [x,y,z]
  7     scale obj [x,y,z]
  8     rotate obj (eulerangles x y z)
  9     rot = eulerangles x y z --建立一个四元数旋转,可以在需要地方使用
 10 5 max commands in maxscript 
 11     n addition to controlling modeling and animation, MAXScript scripts can invoke 3ds Max menu and toolbar commands. You do this using the "max" keyword.
 12     for example:
 13         max file open
 14         max unhide all
 15         max quick render
 16     help:
 17         max time ?
 18         max sel ?
 19         max ?
 20 
 21 6 select
 22     select obj --单选,选择当前,之前的被释放
 23     selectmore obj --多选
 24     deselect obj
 25     deselectNode node
 26 
 27     clearselection() --清空所有
 28 
 29     max select all
 30     max select child --每调用一次,选中一个节点
 31 7 show class "*"
 32     show class "box"
 33     show class "box.*"
 34 8 --exit 跳出循环,而不是使用break
 35 9 --函数
 36      function myFunc x y = () --普通函数,调用: myFunc 3 4
 37      function myFunc x y:20 = () --带默认参数的函数,调用:myFunc 3或 myFunc 3 y:4
 38      function myFunc x:10 y:20 = () --全默认参数函数,调用: myFunc x:3 y:4或myFunc y:4 x:3
 39 10 --文件操作相关
 40     getFilenamePath "c:/test/abc.txt" --"c:\test\"
 41     getOpenFileName 
 42         caption:"Render To Texture Object Presets Open" 
 43         filename:(getDir #renderPresets + @"") 
 44         types:"Object Preset(*.rtp)|*.rtp" 
 45         historyCategory:"RTTObjectPresets"
 46     getSavePath caption:"my title" initialDir:"$scripts"
 47     file="g:\\subdir1\\subdir2\\myImage.jpg"
 48 
 49     filenameFromPath file -- returns: "myImage.jpg"
 50     getFilenamePath file -- returns: "g:\subdir1\subdir2\"
 51     getFilenameFile file -- returns: "myImage"
 52     getFilenameType file -- returns: ".jpg"
 53     pathIsNetworkPath "c:\\temp\\test.txt" --returns: false
 54     pathIsNetworkPath "\\\\someserver\\temp\\test.txt" --returns: true
 55 11 --string 
 56     findString "Thanks for all the fish!" "all" -- returns 12
 57     filterString "MAX Script, is-dead-funky" ", -" --#("MAX","Script","is","dead","funky")
 58     s1=replace "1234567890" 5 3 "inserted string" --"1234inserted string890"
 59 
 60     s ="Balerofon"
 61     ss = substring s 5 3-- returns "rof"
 62     ss = substring s 5 -1-- returns "rofon"
 63     ss = substring s 5 100-- returns "rofon"
 64 
 65     s="text1"
 66     matchPattern s pattern:"text?"-- returns true
 67     matchPattern s pattern:"T*"-- returns true
 68     matchPattern s pattern:"T*"ignoreCase:false-- returns false
 69     matchPattern s pattern:"s*"-- returns false
 70     
 71     trimright "MAXScript \n " --spaces and new line trimmed
 72     --"MAXScript"
 73     trimright "$Teapot0911" "1234567890" --remove trailing numbers
 74     --"$Teapot"
 75 
 76 12 --Working with Values
 77     --------------------------------------------------------
 78                     ClassOf                 SuperClassOf
 79     --------------------------------------------------------
 80     b                Box                        GeometryClass
 81     box                GeometryClass            Node
 82     GeometryClass    Node                    MAXWrapper
 83     Node            MAXWrapper                Value
 84     MAXWrapper        Value                    Value
 85     Value            Value                    Value
 86     --------------------------------------------------------
 87 
 88     --FOR EXAMPLE
 89     --either of the following will collect all objects of class box into variable allBoxes :
 90     allBoxes=for obj in $* where (isKindOf obj box) collect obj
 91     allBoxes=#()
 92     for obj in $* do (if classOf obj == box then append allBoxes obj)
 93     
 94     --the following function limits the choices to shape objects:
 95     fn shape_filt obj = isKindOf obj Shape
 96 13 --数组相关操作
 97     --赋值
 98     arr = #()
 99     append arr 3
100     append arr "hello"
101     arr[3] = 12.2
102 
103     --遍历
104     for o in arr do print o
105     for i=1 to arr.count print arr[i]
106 
107 14 --maxscript language reference -collections
108     --ObjectSets represent the main scene object categories in 3ds Max. 
109        objects  --all the objects
110     geometry  --the standard 3ds Max categories...
111     lights
112     cameras
113     helpers
114     shapes
115     systems
116     spacewarps
117     selection  --the current selection
118 
119     --for example
120     for s in shapes do print s
121     for i=1 to geometry.count do print geometry[i]
122 15 --rootscene 与 rootnode
123     rootNode 
124     ------------------------------------------------------------------------------------------
125     Contains a Node value that defines the root node of the scene.
126     The root node does not physically exist in the scene, rather it is a special node that is the parent node of all nodes that are not linked to another node.
127     The scene objects can be enumerated by accessing the children property of the root node.
128     A run-time error is generated if you try to perform other node operations on the root node.
129        
130     rootScene 
131     ------------------------------------------------------------------------------------------
132     Represents the scene root in scripts and Macro Recorder output.
133     The subAnims of rootScene include the node hierarchy, the Material Editor, Track View, Scene Material Library etc
134 
135     --遍历场景中最顶级的物体
136     for o in rootNode.children do
137     (
138         print o
139         print o.parent --undefined
140     )
141 
142     --注意,MAX场景是以树结构来组织的,一个场景可以多个不相连的子树,也就是有多个根结点
143     --这些子树都以rootnode为根,但parent却是undefined,如上
144 
145     --导出FBX模型与动画
146     --1,导出模型和骨骼层级
147     --注意:骨骼层级必须和模型一起导出,否则对它设置动画无效果,这个很容易忽视
148     
149     --等价于 select geometry
150     for o in objects do
151     (
152         cls = classof o
153         if cls == Biped_Object or cls == BoneGeometry or cls == PolyMeshObject  then
154         (--选择所有网格,和所有骨骼(biped_object, boneGeometry)
155             selectmore o
156         )
157         
158     )
159 
160     --2,导出不带模型的纯动画
161     for o in objects do
162     (
163         cls = classof o
164         if cls == Biped_Object or cls == BoneGeometry then
165         (--所有骨骼(biped_object, boneGeometry)
166             selectmore o
167         )
168     )
169 16 --material
170     ------------------------------------------------------------------------------------------
171     --The following will render the diffuse map assigned to the material of object $foo
172     -- to a bitmap of size 640x480 and save it to the file "foodif.bmp"
173     ------------------------------------------------------------------------------------------
174     rm = renderMap $foo.material.diffuseMap size:[640,480] \
175     fileName:"foodif.bmp"
176     save rm
177     close rm
178 
179     ------------------------------------------------------------------------------------------
180     --材质,每个模型只有一个material,但这个material可以是单材质或多重材质
181     --每个材质可以有多个贴图,对应各种颜色: 
182     --diffusemap :漫反射
183     --不透明贴图:不透明度
184     --高光贴图:高光颜色
185     --光泽度贴图:光泽度
186     --自发光贴图:自发光
187     --凹凸贴图,反射贴图,折射贴图,置换贴图。。。。
188     ------------------------------------------------------------------------------------------
189     showTextureMap $foo.material $foo.material.diffuseMap on
190     tm = checker()
191     mat = standardMaterial diffuseMap:tm
192     mm = multimaterial() --多重材质
193     mm[1] = mat
194     $box01.material = mm
195     showTextureMap mm[1] tm on
196 
197     getnumsubmtls --获取子材质数量
198     
199     -----------------------------------------------------------
200     --如何获取模型上的贴图
201     b = box()
202     b.material.diffuseMap.filename --203     b.material.diffuseMap.bitmap
204 17 --show properites
205     b = box()
206     showproperties b.material
207 18 --external command
208     --注意,DOS命令是WINDOWS网格的分割符,是下坡线,maxscript是上坡线,必须转换
209     doscommand "copy f:\\abc.fbx f:\\test" --将 f:\abc.fbx拷贝到f:\test文件夹下
View Code

 

推荐阅读