PDA

View Full Version : floaters: isChecked/closeDialogs not working as expected


Jon Huhn
10-20-2005, 09:36 AM
As I'm getting up to speed in programming in Maxscript, I'm at a point where I need to learn to build robust GUI elements for the tools I'm building.

So right now I'm trying to learn to build a floating rollout that can be toggled on and off with a toolbar button. I'm using the isChecked/closeDialogs handlers to toggle the button state on/off. So far so good.

My problem is when I close the floater by pressing the standard Windows "x" button in the top right corner of the floater window, the floater closes all right, but the button on the toolbar remains in the "checked" position.

I know it's possible to have the toolbar button uncheck itself when the rollout floater is closed with the "x" button, because the Bone Tools floater does it properly, but I haven't been able to figure out where in that file ( Macro_BoneAdjustmentsTools.mcr ) it's specified.

Does anyone know how I can get my toolbar button to uncheck itself when the floater is closed with the "x" button?

Thanks!

Light
10-20-2005, 09:59 AM
Jon,

Maybe this does what you need:

macroScript vToggle category:"Light's Orionflame" buttonText:"Toggle" tooltip:"Toggle"
(
local pState = true
on isChecked return pState
on execute do
(
pState = true
rollout new "" (on new close do (pState = false; updateToolbarButtons()))
createDialog new 300 200
)
)





Light

Jon Huhn
10-20-2005, 11:02 AM
Light,

Thanks for your example. It seems to work in your script, but I'm using a rollout floater instead of a dialog, and I can't figure out how to get it to work with the isChecked/closeDialogs paradigm...

Light
10-20-2005, 11:45 AM
Here you go:

macroScript vToggle category:"Light's Orionflame" buttonText:"Toggle" tooltip:"Toggle"
(
local pState = false
on isChecked return pState
on execute do
(
pState = true
local rToggle = newRolloutFloater "NEW" 300 200
rollout new "" (on new close do (pState = false; updateToolbarButtons()))
addRollout new rToggle
)
)




Light

Jon Huhn
10-20-2005, 01:02 PM
Light,

Could you explain to me what's happening in this script? I can't find reference in the Maxscript reference for what you did in this line:

rollout new "" (on new close do (pState = false; updateToolbarButtons()))

Light
10-20-2005, 01:07 PM
That line is a rollout definition. Close event is called when the rollout is closed, which assigns false to pState variable and then forces max to update button states in all toolbars.




Light

Jon Huhn
10-20-2005, 03:15 PM
Thanks, Light. Since I'm new to Maxscript, it's going to take a little while to digest what's going on exactly, but I think you've given me enought to start digging on my on. Thank you.

I'm curious what good the closeDialogs handler is then, if it's not needed in order to change the state of the button back to "unchecked". Your method here is superior because it actually unchecks the button if the floater is closed by hitting the windows "x" button. The closeDialogs handler doesn't do that.

Light
10-20-2005, 03:47 PM
If you mean destroyDialog by closeDialog, you can use it to destroy a dialog, and when you do so, maxscript will look for a close event handler. If present, it will call it.

Basically:
destroyDialog -> close the dialog and call close event handler [if present]
close event handler -> what needs to be done when the dialog is closed

Also remember that maxscript will call a close event handler if you close a dialog by using the "x" button, alt + f4 and even by a destroyDialog call from the listener.

You can also check out the open event handler, which is called when a dialog is created. IE on dialogName open do ()





Light

Jon Huhn
10-20-2005, 03:54 PM
Actually, I did mean closeDialogs. It's new to Max 7 (remember, since I'm just learning all this for the first time, I'm tied very closely to the MaxScript reference, which is why I was so insistent on using the handler described there. But your's is working far better :) )

From the MaxScript reference, Contents/MaxScript Tools and Interaction with 3ds max/Creating MaxScript Tools/Defining Macro Scripts:


NEW in 3ds max 7:The closeDialogsis handler is called instead of the on Execute handler whenever the isChecked handler returns true (the button / icon / item is checked ). It can be used to TOGGLE back to the unchecked state. This handler should implement any cleanup code that closes any open dialogs and basically returns the macroScript to a pre-executed state.
Note:

The closeDialogs handler depends on the existence of the isChecked handler. If anon closeDialogshandler is defined without an isChecked handler to be defined, a compile-time error will be thrown!

Light
10-20-2005, 04:19 PM
OK, how about this that does both:

macroScript vLight category:"Anti-Lock Brake System" buttonText:"Toggle" tooltip:"Toggle"
(
local dialogOpen = false, new
on isChecked do dialogOpen
on execute do
(
new = newRolloutFloater "New" 300 200
rollout rNew "" (on rNew close do (dialogOpen = false; updateToolbarButtons()))
dialogOpen = true
addRollout rNew new
)
on closeDialogs do (closeRolloutFloater new; dialogOpen = false)
)





Light

Jon Huhn
10-20-2005, 04:48 PM
Works like a charm! Thanks so much!

CGTalk Moderation
10-20-2005, 04:48 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.