View Full Version : execute a script with a custom attribute CheckButton ?
03-27-2008, 06:18 PM
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 (http://forums.cgsociety.org/showthread.php?f=98&t=612919) and wrestling with custom atts (http://forums.cgsociety.org/showthread.php?p=5045924#post5045924). 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
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 "\n 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\n 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?
03-28-2008, 04:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.