Getting Started with Max Script

MAXscript is the built-in scripting language of 3ds Max, a function added in Max2.0 and later. Can also be used in 3ds Max related products such as Autodesk VIZ, character studio, Plasma and GMax; scripts can be used for modeling, animation, materials, rendering and more. It is specially designed for 3D Studio Max. – Excerpted from Baidu Encyclopedia

1. Enable max script

  • Open the max script menu in the 3d max software and open the max script listener, which is an interactive interface where script code can be entered.
  • In the max script menu, open the max script editor to edit the script file. The main advantage is that it has highlighting, and other editors can also be used.
  • In the max script menu, select Run Script and select the script location to run the customized script file.

2. Data Type

1. int
2. float
3. string
4. array Each element of the array can be different, and the subscript 1starts from

1 +2
3
1.0+2.0
3.0
a = "hello"
"hello"
#(1,2,3,"asd",[12,3])
#(1, 2, 3, "asd", [12,3])
a = #(1,2,4,4)
#(1, 2, 4, 4)
a[1]
1
a[3]
4

5. Type conversion

a = 1
1
a as string
"1"
a = "1"
"1"
a as float
1.0
a = "1.0"
"1.0"
a as integer
1

6. Structure
struct <struct_name> ( <member> , <member> )
declaration: Struct person (name, height, age, sex)
instantiation:Bill = person name:"Bill" height:72 age:34 sex:#male

3. Basic use

basic math operations

2*3
6
pi *2
6.28319
2 ^3
8
"asd"+"def"
"asddef"
random 1 100   // 生成1 -100 的随机数
1
random 1.0 100
56.6555
x =1
1
x+=1
2

modeling operation

  • generate a box case-insensitive

    1. Box()
    2. mybox = Box()Parentheses are required after no parameters
    3. mybox = box length:20 width:20 height:20Generated boxwith certain parameters. Similar to a function call, without parentheses, followed by
      parameters boxThe default name of the generated box isBox001
  • get onebox

    1. $Box001use object name
    2. myboxuse variable names
  • Modify properties

    1. $Box001.width=100
    2. mybox.length=100
    3. mybox.wirecolor = (color 255 0 255)
    4. mybox.scale = [1.5,1.5,1.5]
  • transform

    1. move mybox [10,0,0]move
    2. scale name_obj [<x,y,z>]zoom
    3. rot_box = eulerangles 0 30 0
      rotate mybox rot_box
      To rotate, you need to set a rotation angle first, and then rotate, which can be regarded as a function call
  • Add modifier
    addModifier mybox (twist angle:30)
    Change modifier properties
    mybox.twist.angle = 60
    Get modifier properties

showclass "twist.*"
Twist(扭曲) : modifier {90,0}
  .axis(轴) : integer
  .bias(偏移) : float
  .angle(角度) : float
  .limit(限制) : boolean
  .upperlimit(上限) : float
  .lowerlimit(下限) : float
OK
  • Get all properties of a modifier
showclass "box.*"
Box(长方体) : GeometryClass {10,0}
  .height(高度) : float
  .length(长度) : float
  .lengthsegs : integer
  .width(宽度) : float
  .widthsegs : integer
  .mapcoords : boolean
  .heightsegs(高度分段) : integer

4. Grammar

condition
if mybox.height == 10 then mybox.width = 20

cycle

for i = 1 to 5 do
(
box_copy = copy mybox
box_copy.pos = [i * 50, 0, 0]
)

set interval

for i = 1 to 5 by 2 do
(
box_copy = copy mybox
box_copy.pos = [i * 50, 0, 0]
)

use

arr = for i=1 to 5 collect i
#(1, 2, 3, 4, 5)

for i in arr do print i
1
2
3
4
5
OK

for i = 1 to arr.count do print arr[i]
1
2
3
4
5

do while loop

do <expr> while <expr> -- do loop
while <expr> do <expr> -- while loop

x=10
while x>0 do print (x-=1)
9
8
7
6
5
4
3
2
1
0
0

x=10
do print (x-=1) while x>10

local and global variables

for i = 1 to 3 do
(
local rad = 10
s = sphere()
s.pos.x = i * 10
s.radius = rad
)

global rad = 10
sphere radius:rad

5. Functions

  • function call
    1. [function name arguments]
    2. [function name parameter name: value parameter name: value]
  • function definition
    1. [fn function name parameter = (...)]
    2. [function function name parameter 1: value parameter 2: value = ()]
      If there are multiple parameters, just stack them
// 方式二
function sig num:0 test:"2" =
(
if num==0
then messagebox("0")
else if num ==1
then messagebox ("1")
else messagebox("2")
messagebox(test)
)

sig test:"3" num:0 

// 方式一
fn si temp = 
(
    messagebox(temp)
)    
si "data"

6. Import and export

  • import
    importFile "C:\Users\uux\Desktop\576.obj" #noPrompt
  • export
    exportFile "C:\Users\uux\Desktop\5761.obj" #noPrompt
  • reset scene
    resetMaxFile #nopromptsilent

7. Application Examples

Learning max script mainly requires batch refinement of obj files. The following is the operation code.

for i =0 to 590 do
(
    resetMaxFile #noprompt
    url1 = "F:\m\seg" +i as string + ".obj"; -- 获得文件名
    url2 = "F:\\nm\seg" +i as string + ".obj";
    importFile url1 #noPrompt -- 导入
    addmodifier $default (tessellate tension:0) -- 增加细化修改器
    $default.tessellate.iterations = 1    -- 修改迭代次数
    exportFile url2 #noPrompt    -- 导出
)

8. Summary

The max script script is a very useful language. Using the script, you can basically realize most of the operations of the graphical interface, and you can quickly perform batch model operations. At the same time, you can also generate animation, modeling, model adjustment and other operations, which can be larger Increase productivity. The first time I contacted it, I didn't know the max script very well. If there are any mistakes, please point out.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325766923&siteId=291194637