MAXScript101_4.1 Loops and Loop Control
1. The While loop
while <test_expr> do <body_expr>
eg.
-- get an object's full path name
fn get_pathname obj =
(
local pn = obj.name
-- repeat while there are more parents
while obj.parent != undefined do
(
-- follow link out to next parent & prepend its name
obj = obj.parent
pn = obj.name + "/" + pn
)
"$" + pn
)
-- usage:
get_pathname $Bip01
--"$Bip01"
get_pathname $Bip01LCalf
--"$Bip01/Bip01 Pelvis/Bip01 Spine/Bip01 L Thigh/Bip01 L Calf"
2. Loop Control
Continue Command: 不执行continue之后的语句,直接下一个循环
eg.
--如果在被选的物体中,存在非Editable_Mesh的物体,则弹出对话框并执行下一个循环语句;
-- 统计Editable_Mesh的物体的个数,面的总数及定点的综述
-- scan all in selection
Exit Command:跳出循环
-- 场景:两个小球分别沿着一个轨道运懂,
-- 当两小球运动到两者间距离最短时,将spray放到两小球中间,并且开始释放
Return Command: 结束整个程序
function findByUserProp propName propValue =
(
-- 如果找到某一obj,它存在参数提供的propValue,则返回该obj;
for obj in objects do
if getUserProp obj propName == propValue then
return obj
-- 否则,返回undefined
undefined
)
-- getUserProp <node> <key_string>
返回结点的用户属性,如果不存在,则返回undefined
视频教程: http://vimeo.com/19514070