PDA

View Full Version : global condition


loran
10-14-2009, 03:13 PM
I want to define globals to enable /disable buttons on conditions.
I don't know where to say that in the code...

if isValidNode $'kaboom-group' and isValidNode $'BombGizmo' then
(
Compute.enabled = true
test.enabled = true
)

else

(
Compute.enabled = false
test.enabled = false
)

denisT
10-14-2009, 06:02 PM
"
I want to define globals to enable /disable buttons on conditions.
I don't know where to say that in the code...


Usually a button is rollout control. You can set button's enable/disable and any other rollout controls parameters on <rollout> open event.


global button_state = if button_state == undefined then on else button_state

try(destroydialog test) catch()
rollout test "test
(
checkbutton bt_on "ON" across:2 width:40 enabled:(not button_state) checked:(button_state)
checkbutton bt_off "OFF" width:40 enabled:(not button_state) checked:(button_state)

on bt_on changed state do bt_on.enabled = bt_off.checked = not (bt_off.enabled = button_state = state)
on bt_off changed state do bt_off.enabled = bt_on.checked = button_state = not (bt_on.enabled = state)
on test open do
(
bt_on.enabled = bt_off.checked = not (bt_on.checked = bt_off.enabled = button_state)
)
)
createdialog test

loran
10-14-2009, 06:42 PM
that s not really what I m looking for. I want a some buttons disabled if 'kaboom-group' doesnt exist in the scene. then enabled when it does exist...

PiXeL_MoNKeY
10-14-2009, 07:04 PM
denisT code should do that. If you are wanting to do it with the dialog open, vs setting it when you open the dialog then you will have to look at callbacks to manage that.

-Eric

denisT
10-14-2009, 07:14 PM
that s not really what I m looking for. I want a some buttons disabled if 'kaboom-group' doesnt exist in the scene. then enabled when it does exist...

it's technically not but really is what you are looking for. :)

loran
10-14-2009, 07:21 PM
thank you guy, I have some work to understand all this :/ will try

and Pixel_Monkey, I m really afraid of that freaky evil monkey!

PiXeL_MoNKeY
10-14-2009, 07:40 PM
Well the "on <rollout> open do" event handler basically says when this rollout opens execute this code. So as long as you place the needed code in there it will execute every time the dialog is launched. The information is pretty well documented in the examples and the "Utilities and Rollout Properties, Methods, and Event Handlers" and "CreateDialog" sections of the Maxscript help.

Oh and don't worry he is Sponge Bob Friendly, you only have to worry if your name is Chris Griffin.

-Eric

loran
10-14-2009, 08:27 PM
I don't speak about doing things on rollout open...
I want some buttons disabled if '$.MyGroup01' doesnt exist in the scene. then auto enabled if '$.MyGroup01' has been created later (without re-open the rollout)

PiXeL_MoNKeY
10-14-2009, 08:47 PM
Then you would put the check in the on open event handler, but you would also want to add a General Event callback or Node Event System callback. Look those up in the help, you could use either an added or name changed handler. Then you would also want to add an "on close <rollout> do" and inside of it delete the callbacks. So whenever you open the dialog it makes the check, then the event handlers are enabled to monitor changes in the scene. On dialog close the callbacks are removed to stop the monitoring as it is no longer needed.

Hope that helps,
-Eric

loran
10-14-2009, 09:10 PM
thank you, I will digg this

denisT
10-14-2009, 09:18 PM
I don't speak about doing things on rollout open...
I want some buttons disabled if '$.MyGroup01' doesnt exist in the scene. then auto enabled if '$.MyGroup01' has been created later (without re-open the rollout)

that's absolutely different story...

in this case you have to use callbacks...


global test_rollout
global controlled_name = "controlled_node"
callbacks.removescripts id:#node_control
fn canUpdate = (iskindof test_rollout RolloutClass and test_rollout.open)
fn debugPrint act state params =
(
format "%: exists:% params:%\n" act state params
)
fn onSceneNodeChanged act:"" = if canUpdate() do
(
local node = callbacks.notificationParam()
local bt = getproperty test_rollout #bt_node
local name = controlled_name
case act of
(
#deleted: if isvalidnode node and node.name == name do bt.enabled = off
#added: if isvalidnode node and node.name == name do bt.enabled = on
#nameset: if isvalidnode node[3] do
(
if node[2] == name then bt.enabled = on
else if node[1] == name and node[2] != name do bt.enabled = off

)
default: bt.enabled = (getnodebyname name != undefined)
)
debugPrint act bt.enabled node
)
try(destroydialog test_rollout) catch()
rollout test_rollout "Node Control"
(
button bt_node "Select Controlled Node" width:190
on bt_node pressed do undo "Select" on
(
if (node = getnodebyname controlled_name) != undefined then select node
else clearSelection()
)
on test_rollout open do
(
bt_node.enabled = (getnodebyname controlled_name != undefined)
callbacks.removescripts id:#node_control

callbacks.addscript #nodePreDelete ("onSceneNodeChanged act:#deleted") id:#node_control
callbacks.addscript #sceneNodeAdded ("onSceneNodeChanged act:#added") id:#node_control
callbacks.addscript #nodeNameSet ("onSceneNodeChanged act:#nameset") id:#node_control
callbacks.addscript #sceneUndo ("onSceneNodeChanged act:#undo") id:#node_control
callbacks.addscript #sceneRedo ("onSceneNodeChanged act:#redo") id:#node_control
callbacks.addscript #systemPostNew ("onSceneNodeChanged act:#new") id:#node_control
callbacks.addscript #systemPostReset ("onSceneNodeChanged act:#reset") id:#node_control
callbacks.addscript #filePostOpen ("onSceneNodeChanged act:#open") id:#node_control
)
on test_rollout close do
(
callbacks.removescripts id:#node_control
)
)
createdialog test_rollout width:200


don't say that it's not really what you want...

-- bug fixed in the snippet... 10.17.2009

denisT
10-14-2009, 09:27 PM
my last script controls node with name "controlled_node". Use controlled_name global variable to set the controlled node name.

CGTalk Moderation
10-14-2009, 09:27 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.