ScriptSpot

Forum topic · General Scripting

How to control Custom Attributes?

By ausn · 2009-04-13

Description

Hello everybody!

I wanna add a custom attributes to a spline to control the animation. I added a listbox and a pickbutton to it, and gonna achieve this: picked an object then the object's name display in the listbox item.

Here's my script:
testCA = attributes listBoxTest
(
parameters main rollout:params
(
-------------------------------------------------------
)

rollout params "Test"
(
fn shapesOnly obj = isKindOf obj shape

listBox objLb ""
pickbutton objPb "Pick an Object" filter:shapesOnly

on objPb picked obj do
objLb.items = #(obj.name)
)
)

custAttributes.add $.modifiers[1] testCA

But when I selected another object then select the object again, the data was gone.
So how to save the data? I know that I should set some parameters but how to do it?

Thank you.

Comments (1)

ausn · 2009-04-16

I’ve read the MAXScript Help file again and rewrite it:

rollout paramsRoll "Parameters"
(
fn shapesOnly obj = isKindOf obj shape

listBox objLb ""
pickbutton objPb "Pick an Object" filter:shapesOnly

on objPb picked obj do
(
append $Point01.modifiers[1].listBoxTest.nodes obj
append $Point01.modifiers[1].listBoxTest.nodesNames obj.name
objLb.items = $Point01.modifiers[1].listBoxTest.nodesNames as array
)

on paramsRoll open do
(
objLb.items = $Point01.modifiers[1].listBoxTest.nodesNames as array
)

on paramsRoll close do
(
local lastDialogPos = getDialogPos paramsRoll
$Point01.modifiers[1].listBoxTest.dialogPos[1] = lastDialogPos.x
$Point01.modifiers[1].listBoxTest.dialogPos[2] = lastDialogPos.y
)
)

testCA = attributes listBoxTest
(
parameters main rollout:ctrlRoll
(
nodes type:#nodeTab tabSizeVariable:true
nodesNames type:#stringTab tabSizeVariable:true
dialogPos type:#intTab tabSize:2
)

rollout ctrlRoll "Control"
(
button floatBt "Float..."

on floatBt pressed do
createDialog paramsRoll 168 215 dialogPos[1] dialogPos[2]
)
)

addModifier $ (emptyModifier())
custAttributes.add $.modifiers[1] testCA

This time it worked very well.