Notifications
Clear all

[Closed] saving Edittext text after running macroscript again

hi

I have a simple macroscript on my toolbar : edittext and a button. When I select a box in my scene and hit the button, a name of the selected box appears in the edittext.How can I do that if I close the script window and run the script again, the name of the box will be still there?

thx for any help

edit

oh and when I restart 3ds max or reset a scene and run this macroscript I don’t want the name of the box in the edittext

3 Replies

You can use a global variable for that, like this:

if myGlobalVar == undefined do global myGlobalVar = ""

try destroyDialog myRol catch ()
rollout myRol ""
(
	editText et "" text:myGlobalVar
	
	on et changed val do
		myGlobalVar = val
)
createDialog myRol

If you really need to reset it to “” after each reset, you can use a callback for that (e.g. #systemPostReset), buf of course then it’s a bit more complicated as you don’t want to cummulate the callbacks. Either you may want to get rid of it first and define something like “global myGlobalVar = “”” in its function part with execution of your script or if you run it quite often, work out the logics to have it added only once.

Hi,
Either what Swordslayer wrote, or use a .ini file to store the value when the script closes and read it when it opens.
something like:


 rollout rol "rol"
 (
 local myINI =  "myINI.ini"
 edittext edt
 
 on rol open do
 (
    edt.text = getINIsetting myINI  "rolparams" "edt"
 )
 on rol close do
 (
    setINIsetting myINI  "rolparams" "edt" edt.text"
 )
 )

Or you could use custom file properties. Or have a null point helper in the scene with user defined object properties. Or you can use persistent global variables like I do

With all my macroscripts that have UI elements that are changeable, I use a couple of functions to save and restore persistent global variables of the UI settings. This way the UI settings get saved with each max file.

Obviously you’d have to change the name MCRnameDialog to match your rollout name.


   
   fn uiInit =
   (
   	for currentControl in MCRnameDialog.controls do 
   	(	try
   		(	pgVarName = "perGlobUI_" + currentControl.name
   			case classof currentControl of
   			(	SpinnerControl:		(	currentControl.value = (execute pgVarName))
   				CheckBoxControl:		(	currentControl.state = (execute pgVarName))
   				RadioControl:			(	currentControl.state = (execute pgVarName))
   				ComboBoxControl:	(	currentControl.selection = (execute pgVarName))
   				EditTextControl:		(	currentControl.text = (execute pgVarName))
   				ProgressBar:			(	currentControl.value = (execute pgVarName)
   												currentControl.color = (execute (pgVarName + "Color")))
   				SliderControl:			(	currentControl.value = (execute pgVarName))
   				
   			)
   			currentControl.enabled = (execute (pgVarName + "Enabled"))
   			currentControl.visible = (execute (pgVarName + "Visible"))
   		)catch()
   	)
   )
   
   
   fn uiSave =
   (
   	for currentControl in MCRnameDialog.controls do 
   	(	try
   		(	pgVarName ="persistent global " + "perGlobUI_" + currentControl.name
   			case classof currentControl of
   			(	SpinnerControl:		(	execute (pgVarName + " = " + (currentControl.value as string)))
   				CheckBoxControl:		(	execute (pgVarName + " = " + (currentControl.state as string)))
   				RadioControl:			(	execute (pgVarName + " = " + (currentControl.state as string)))
   				ComboBoxControl:	(	execute (pgVarName + " = " + (currentControl.selection as string)))
   				EditTextControl:		(	execute (pgVarName + " = \"" + (currentControl.text) +"\""))
   				ProgressBar:			(	execute (pgVarName + " = " + (currentControl.value as string))
   												execute (pgVarName + "Color" + " = " + (currentControl.color as string)))
   				SliderControl:			(	execute (pgVarName + " = " + (currentControl.value as string)))
   			)
   			execute (pgVarName + "Enabled" + " = " + (currentControl.enabled as string))
   			execute ((pgVarName + "Visible") + " = " + (currentControl.visible as string))
   		)catch()
   	)
   )
   
   on MCRnameDialog open do uiInit()
   
   on MCRnameDialog close do uiSave()