Notifications
Clear all

[Closed] Can Rollouts remember last time states?

Hi,all
I have a question, The scripts have four rollouts ,Can the rollouts remember their states from the last time the floater was used?
Thanks!!

(
global testTabs
try(destroyDialog testTabs )catch()

local LastSubRollout = 1

rollout testTabsRollout01 "Rollout 01"
(
	spinner spn_spinner "Spinner"
)
rollout testTabsRollout02 "Rollout 02"
(
	button btn_button "Button"
)
rollout testTabsRollout03 "Rollout 03"
(
	label lbl_label "This is some text"
)
rollout testTabsRollout04 "Rollout 04"
(
	colorpicker clr_picker "Color Picker"
)
rollout testTabsRollout05 "Rollout 05"
(
	checkbox chk_box "Checkbox"
)

testTabs_Rollouts = #(
	#("Tab One",#(testTabsRollout01)),
	#("Tab Two",#(testTabsRollout02)),
	#("Tab Three",#(testTabsRollout03)),
	#("Tab Four",#(testTabsRollout04,testTabsRollout05))
)	

rollout testTabs "Test Tabs"
(
		dotNetControl dn_tabs "System.Windows.Forms.TabControl" height:20 width:420 align:#center
		subRollout theSubRollout width:420 height:140 align:#center
		
		on dn_tabs Selected itm do
		(
			if LastSubRollout != (itm.TabPageIndex+1) do --do not update if the same tab clicked twice
			(
				for subroll in testTabs_Rollouts[LastSubRollout][2] do
					removeSubRollout theSubRollout subroll
				for subroll in testTabs_Rollouts[LastSubRollout = itm.TabPageIndex+1][2] do	
					addSubRollout theSubRollout subroll
			) 
		)--end tabs clicked		
		
		on testTabs open do
		(
			for aTab in testTabs_Rollouts do
			(
				dn_tabs.TabPages.add aTab[1]
			)
			for subroll in testTabs_Rollouts[1][2] do 
				addSubRollout theSubRollout subroll				
		)
)

createDialog testTabs 440 200

)

5 Replies

Hi there,

One way of doing it is to set the state of the ui items to an ini file when the close event is triggered, then when it’s opened, use the open event to restore the items by retrieving the values from the ini.

Can you Explained it detailedly ? Sorry, I know very little in this field,
Moreover, The script use dotNet, difference with ordinary Rollouts .

I’m including an example. Evaluate it, and change the spinner values and colors to whatever you want. When you re-evaluate it, it should hold the same values as when you closed it.

(
 	rollout dialog_test "Test"
 	(
 		local iniData = ( (getDir #scripts) + "\\scriptData.ini")
 		
 		spinner sp_01 "Spinner 01"
 		spinner sp_02 "Spinner 02"
 		colorPicker cp_01 "Color Picker 01"
 		
 		on dialog_test open do
 		(
 			if (doesFileExist iniData) == true do
 			(
 				sp_01_data = getIniSetting iniData "Data" sp_01.name
 				sp_02_data = getIniSetting iniData "Data" sp_02.name
 				cp_01_data = getIniSetting iniData "Data" cp_01.name
 				
 				if sp_01_data != "" do sp_01.value = (execute sp_01_data)
 				if sp_02_data != "" do sp_02.value = (execute sp_02_data)
 				if cp_01_data != "" do cp_01.color = (execute cp_01_data)
 			)
 		)
 		
 		on dialog_test close do
 		(
 			setIniSetting iniData "Data" sp_01.name (sp_01.value as string)
 			setIniSetting iniData "Data" sp_02.name (sp_02.value as string)
 			setIniSetting iniData "Data" cp_01.name (cp_01.color as string)
 		)
 	)
 	createDialog dialog_test
 )

You would just have it being handled through createDialog’s open/close event. I would actually do this through functions and loops to keep it more generic, but for the sake of keeping it simple I just made it more straight forward. You can also check out the MAXscript help file for more info on INIs.

If you only care about within a single session of max you can also use a global variable.

I like to embed all my script info into a single struct.

Scriptvars.Quantity = 1
Scriptvars.Speed = 2
Scriptvars.Value = 3
Scriptvars.list = #(1,2,3,4,5)

Thanks labbejason thatoneguy,Your suggestion is helpful to me,I am also looking for some information,for example:

(
global testRolloutFloater
local theIniFile = GetDir #plugcfg + “\ estRolloutFloater.ini”
rollout firstRollout “First Rollout”
(
spinner spn_someValue “Spinner”
on spn_someValue changed val do
(
–store the spinner’s value
setIniSetting theIniFile “SomeValue” “Value” (val as string)
)
on firstRollout moved pos do
(
–only the first rollout in a floater will get this handler called
–when the floater is moved. Use to restore the floater’s position.
setIniSetting theIniFile “Floater” “Position” (pos as string)
)
on firstRollout rolledUp val do
(
–val is true when open, but is used in rolledup: to close, thus invert!
setIniSetting theIniFile “FirstRollout” “Open” ((not val) as string)
)
on firstRollout open do
(
–update any UI controls based on the settings in the INI file.
–if nothing is saved, the result of getINIsetting is “” and (execute “”) gives OK.
–Thus, if the result is OK, there was no value in the INI.
local theVal = execute (getIniSetting theIniFile “SomeValue” “Value”)
if theVal != OK do spn_someValue.value = theVal
)
)

rollout secondRollout “Second Rollout”
(
checkbutton chk_someOption “Check Me!”
on chk_someOption changed val do
(
setIniSetting theIniFile “SomeOption” “Value” (val as string)
)
on secondRollout rolledUp val do
(
setIniSetting theIniFile “SecondRollout” “Open” ((not val) as string)
)
on secondRollout open do
(
local theVal = execute (getIniSetting theIniFile “SomeOption” “Value”)
if theVal != OK do chk_someOption.state = theVal
)
)

try(closeRolloutFloater testRolloutFloater)catch()
local thePos = execute (getIniSetting theIniFile “Floater” “Position”)
if thePos == OK do thePos = [100,100] –if no previous position found, use a default
testRolloutFloater = NewRolloutFloater “Test Floater” 200 120 thePos.x thePos.y

local theVal = execute (getIniSetting theIniFile “FirstRollout” “Open”)
if theVal == OK do theVal = true –if no state found, roll it up!
addRollout firstRollout testRolloutFloater rolledup:theVal

local theVal = execute (getIniSetting theIniFile “SecondRollout” “Open”)
if theVal == OK do theVal = true
addRollout secondRollout testRolloutFloater rolledup:theVal
)

But I still can not find a solution for the script .Please superior help me ,thanks!!