MAXScript101_4.2 Case Expressions
1.
case of
(
(<test_1>): <expr_1>
(<test_2>): <expr_2>
(<test_3>): <expr_3>
-- etc. --
)
if statement:
if distance obj $camera1 > 1000 then
obj.segs = 5
else
obj.segs = 32
case statement:
for obj in geometry do
(
local d = distance obj $cam1
case of
(
(d <= 50): obj.segs = 40
(d <= 120): obj.segs = 25
(d <= 250): obj.segs = 10
default: obj.segs = 5
)
)
case <expr> of
(
<value1>: <expr1>
<value2>: <expr2>
<value3>: <expr3>
-- etc. --
)
eg.
-- radiobuttons 语法:radiobuttons <name> [ <caption> ] labels:<array_of_strings> [default:<number>] [columns:<number>]
radiobuttons cloneType labels: #("Instance", "Reference", "Copy")
-- clone the picked object
newObj = case cloneType.state of
(
1: instance pickedObj -- instance <node>
2: reference pickedObj -- reference <node>
3: copy pickedObj -- copy <node>
)
2. 实例
--Create some scene objects. Select them, then run the script: ( -- 将场景中选中的物体转化为数组变量 local obj_array = selection as array -- 获取场景中选中物体的名字 local obj_name_array = for o in obj_array collect o.name rollout CloneObject "Clone Object" ( -- 创建radiobuttons: copy, instance, reference radiobuttons copy_type labels:#("copy", "instance", "reference") -- 创建radiobuttons: 以场景中选中物体的名字为label radiobuttons which_obj labels:obj_name_array -- computed label array -- 创建按钮,并且更新按钮文本显示 button do_it "Copy Object" fn updateButton = ( do_it.text = case copy_type.state of ( 1: "Copy " -- 1 为数组第一个元素 2: "Instance " 3: "Reference " ) do_it.text += obj_name_array [which_obj.state] )--end fn on copy_type changed state do updateButton() on which_obj changed state do updateButton() on CloneObject open do updateButton() -- 按下按钮,发生的动作 on do_it pressed do ( copyfn = case copy_type.state of ( 1: copy 2: instance 3: reference ) if which_obj.state > 0 do copyfn obj_array[which_obj.state] )--end on pressed )--end rollout if obj_array.count > 0 do createDialog CloneObject )--end script