PDA

View Full Version : Can Rollouts remember their states?


EvilGnome
03-11-2005, 12:36 AM
I have a script with a floater with several rollouts.

I would like to know if it's possible to have the rollouts remember their states from the last time the floater was used?

Bobo
03-11-2005, 12:44 AM
I have a script with a floater with several rollouts.

I would like to know if it's possible to have the rollouts remember their states from the last time the floater was used?

Yes. You would have to store them all in an INI file and restore when opening again.
Will post an example if you want...

Bobo
03-11-2005, 12:57 AM
Yes. You would have to store them all in an INI file and restore when opening again.
Will post an example if you want...


(
global theTestFloater
try(closeRolloutFloater theTestFloater)catch()
local theIniFile = getDir #plugCfg + "/TestRolloutState.ini"
rollout testRollout01 "Test Rollout 01"
(
button testButton "Test"
on testRollout01 close do
setIniSetting theIniFile "Rollout01" "Rolledup" (testRollout01.open as string)
on testRollout01 open do
if (val = execute (getIniSetting theIniFile "Rollout01" "Rolledup")) != OK do testRollout01.open = val
)
rollout testRollout02 "Test Rollout 02"
(
button testButton "Test"
on testRollout02 close do
setIniSetting theIniFile "Rollout02" "Rolledup" (testRollout02.open as string)
on testRollout02 open do
if (val = execute (getIniSetting theIniFile "Rollout02" "Rolledup")) != OK do testRollout02.open = val
)
rollout testRollout03 "Test Rollout 03"
(
button testButton "Test"
on testRollout03 close do
setIniSetting theIniFile "Rollout03" "Rolledup" (testRollout03.open as string)
on testRollout03 open do
if (val = execute (getIniSetting theIniFile "Rollout03" "Rolledup")) != OK do testRollout03.open = val

)

theTestFloater = newRolloutFloater "Test" 200 300
addRollout testRollout01 theTestFloater
addRollout testRollout02 theTestFloater
addRollout testRollout03 theTestFloater
)

EvilGnome
03-11-2005, 01:31 AM
Thanks Bobo!

I'll give it a try.

EvilGnome
03-11-2005, 01:49 AM
Thanks Bobo, that works perfectly.

Just another quick question if you can spare the time!

I'm wondering if I can lock the tool bar button/icon for my script in an "on state" while the floater is open?

Just the way the "Layer Manager button" works for example?

Thanks again!

ofer_z
03-11-2005, 02:15 AM
Thanks Bobo, that works perfectly.

Just another quick question if you can spare the time!

I'm wondering if I can lock the tool bar button/icon for my script in an "on state" while the floater is open?

Just the way the "Layer Manager button" works for example?

Thanks again!


here's a little expamle of how to do this:


macroScript testDialog
buttontext: "test dialog"
category: "Tests"
(
-- declare a local variable that holds the state of the rollout.
-- the reason to use will be explained below.
local testDialgOpen = false

rollout testDialg "test Dialog"
(
-- declare a close button
button cl "close"
on cl pressed do destroyDialog testDialg

-- on closing of the rollout either by the close button or the window "X" button
-- will set the testDialgOpen to false so the toolbar button will be turned off.
on testDialg close do (
testDialgOpen = false
updateToolbarButtons()
)
)-- end rollout definition

-- this is the important part for having the toolbar button stay pressed when the rollout
-- is open. the simple case is to use:
-- on isChecked return testDialg.open
-- however, using this, when closing the rollout using either the close button or the window's "X"
-- will execute the on testDialg close handler before the rollout is actually closed, and so
-- the toolbar button will stay pressed. using a local variable and assigning the rollout state to
-- it solves this issue.
on isChecked return testDialgOpen

-- to use the toolbar button as a toggle we use the code below to test if the rollout is open or not.
-- if it is not, it will be created, otherwise it will be closed.
on execute do (
if testDialg.open then (
destroyDialog testDialg
) else (
createDialog testDialg
)
testDialgOpen = testDialg.Open
updateToolbarButtons()
)-- end on execute handler
)-- end of macroscript



hOpe this helps,
o

Bobo
03-11-2005, 02:36 AM
Ofer's code works in all MAXScript versions since R2.
If you are using MAX 7 though, you can also use the new on closeDialogs do() handler:

macroScript TestFloater category:"Forum Help"
(
global theTestFloater --declare the floater variable
rollout testRollout01 "Test Rollout 01" --define a rollout
(
button testButton "Test"
)
on execute do --define the on execute handler
(
try(closeRolloutFloater theTestFloater)catch() --make sure the floater is closed
theTestFloater = newRolloutFloater "Test" 200 300 --define new floater
addRollout testRollout01 theTestFloater --add the rollout
)
on isChecked return try(theTestFloater.open)catch(false) --return true if floater open, false otherwise

--This handler is called in Max 7 instead of on Execute do
--whenever the on isChecked handler returns true.
--It can be used to cleanup the macro and do everything related to toggling off.
--This is how all shipping toggleable macroScripts in Max 7 have been implemented.
on closeDialogs do closeRolloutFloater theTestFloater

)

EvilGnome
03-11-2005, 03:10 AM
Thanks again Bobo!

CGTalk Moderation
03-11-2005, 03:10 AM
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.