MaxScript Listener用来测试小段代码,测试成功后再写到最终的脚本语言编辑器Eidtor。
故在用Editor写脚本程序时,对于单独的功能可以先在Listener进行测试。故推荐使用两个文件夹:一个用来存放用Listener写的代码,另一个用来存放最终的代码,它应含有错误检查,文档及界面等。ctrl+E,执行代码。
1. 旋转
2. 代码注释用--
3. Macroscripts - 用来自定义快捷键,菜单和按钮
创建了Macroscript,可以与快捷键,菜单和按钮绑定。把一些常用的功能制成Macroscript,方便以后使用。
step1: 在Editor中输入:
MacroScript Random_Rotate category:"Shemmy Tools" buttonText:"Random Rotate" tooltip:"Random Rotate"
(
for obj in $ do -- Loop over currently selected objects
(
randXrot = random -3.0 3.0 -- create a random X rotation value and store as a variable
randYrot = random -3.0 3.0 -- create a random Y rotation value and store as a variable
randZrot = random -3.0 3.0 -- create a random Z rotation value and store as a variable
rot_obj = eulerangles randXrot randYrot randZrot -- Build our rotation object and store
rotate obj rot_obj -- Apply the rotation to the current obj
)
)
保存它并且按ctrl+E执行。如果没有问题的话,在listener窗口中会出现一个数字,但是此时对场景中的物体不产生影响;否则如果有问题,则会在listener窗口中提示错误。
step2: 打开Customize > Customize User Interface, 选则menu标签,在Catergory的下拉中应该能找到Shemmy Tools,同时在Action面板中出现了我们自定义的动作Random Rotate;
step3: 在窗口右边,单击New...键入菜单名称Shemmy Tools。此时在Menus的下拉中能找到该菜单;
step4: 将上一步骤创建的菜单名称Drag and Drop到窗口右边的菜单面板中,再将Action面板中的Random Rotate动作Drag and Drop到该菜单下面,如图示;
step5: 将该菜单保存为另外一个名称,如MaxStartUI2.mnu;
step6: 关掉Customize User Interface这个窗口,到Customize > Load custom UI scheme,选择上述菜单导入。这样,在主菜单条上就会出现Shemmy Tools这个菜单。
注意:第一,如果没有选择场景中的物体,就执行该菜单下的动作会crash; 第二,如果想改变旋转的角度该怎么办?这两个问题是需要解决的。
Practice: 对上次创建的篱笆园,绕X,Y,Z轴随机旋转一个角度。
for obj in $ do
(
randXrot = random -3.0 3.0
randYrot = random -3.0 3.0
randZrot = random -3.0 3.0
rot_obj = eulerangles randXrot randYrot randZrot
rotate obj rot_obj
)