[Closed] execute a script with a custom attribute CheckButton ?
Hello
How can I execute a script with a custom attribute CheckButton (boolean type) ?
For example : hide and unhide an object with a CheckButton
thanks a lot
Hi, Arnaud. The short answer is Yes, you can. Take a look at the following threads: pick button in CustAttribute UI and wrestling with custom atts. The second thread deals specifically with a Boolean-type setup. One of the keys is to have a third-party object/helper to “observe” and supervise the commands.
OK, here’s a script that does what you described (I think:shrug: )…
(
ca = attributes New
(
parameters main rollout:params
(
-- create the attribute
hidestuff type:#boolean ui:ckb_hs
)
rollout params "Checkbox Controller"
(
-- create the checkbox
checkbox ckb_hs "Hide Unselected Stuff"
on ckb_hs changed theState do
(print this.hidestuff)
)
)
rollout demo "CustAtt Checkbox Demo"
(
button btn "Make Shapes"
on btn pressed do
(
-- make two objects
s = sphere radius:12
c = cone pos:[50,0,0]
-- assign the custom attribute to the sphere
custAttributes.add s ca
-- set the initial value of the boolean attribute
s.hidestuff = false
-- create an object to "watch" the state of the sphere's checkbox
watcher = point()
fs = float_script()
watcher.axistripod.controller = fs
-- add the objects the watcher is supposed to watch
fs.addNode "ctrlBall" s
fs.addNode "coneshape" c
/*a float_script always expects to have a float value returned at the end of
the expression. "hide" and "unhide" return a value of "OK". So tack "
0" on
at the end of the expression or the code will throw an error (my thanks to
Tyson Ibele over at SimplyCG for explaining that bit to me :-)*/
fs.script = "if ctrlBall.hidestuff == true then hide coneshape else unhide coneshape
0"
)
)
createDialog demo 200 50
)
Evaluate the code and press the “Make Shapes” button. A sphere and a cone will appear. Select the sphere, open the Modify Panel and you’ll see the “Hide Unselected Stuff” checkbox. Check the box, click on the time slider and the cone disappears. This can also be animated, so the cone can disappear on, say, frame 10 and reappear on frame 20.
Is this what you’re after?