Notifications
Clear all

[Closed] Change button text of Rollout?

Hey all!

I was just wondering if there is a way to change the text of buttons on a rollout, without opening the script, editing and saving?

Ideally I’m looking for a way to right click the button, edit the button text, then for it to be saved, so next time the script is run, the buttons now have the changed names.

Is this possible at all?

Thanks,

Dean

11 Replies
3 Replies
(@arahnoid)
Joined: 11 months ago

Posts: 0

Hi Dean,
Yes this is possible, you can make a right-click event to create another rollout with the input field to set up a new name for button and save the name to *.ini file. So the next time you run script the you will read the name of button from *.ini file ( I’m not sure if saving to *.ini file is the best practices, however it may work).

If nobody will show you an example how to do this then later today I will show it.

(@denist)
Joined: 11 months ago

Posts: 0

everything is possible. but could you give a scenario of its reason? because a solution might vary.

(@deanpunchard)
Joined: 10 months ago

Posts: 0

It’s for a script that changes the Effect ID channel in vray materials. I have a rollout that has 31 buttons, labelled 0-30, and I want to be able to change their text to what ever the user wants. eg button 1 might be changed to “glass” and button 2 to “metal” and so on. This is so all IDs are organised and when using these in compositing the use knows which element is with each ID.
I’m not looking for an automatic system, I use a system like this at the moment, but it means manually altering the button text inside the script. I know it’s not very hard to do, but other people might struggle, so a dynamic method would be best.

Cheers,

Dean

That sounds amazing, if you could show me a basic example I’m sure I could de-construct it and apply it to my script.

Thanks,

Dean

Hi Dean
Have a look at code bellow itmay help


 -- Here locate the path to ini file
 -- in this case "myScript.ini" file will be located in "C:\Program Files\Autodesk\3ds Max 2012\Scripts\MyScriptFoldder"
 ini_file_path = "$Scripts\\MyScriptFolder\\myScript.ini"
 
 -- Here we read button name from ini file
 buttonNamefromINI = (getINISetting ini_file_path "ButtonNames" "magicButton")
 
 --Rollout with main script
 rollout rl_testRollout "Test Rollout" width:400 height:40 
 (
 	button btn_magicButton buttonNamefromINI width:300 height:30
 	
 	-- Lets create event on right click
 	on btn_magicButton rightclick do
 	(
 		try(destroydialog rl_renameMagicButton)catch()
 		createDialog rl_renameMagicButton
 	)
 )
 createDialog rl_testRollout 
 
 
 
 --Rename rollout
 rollout rl_renameMagicButton (("Rename button:"+ rl_testRollout.btn_magicButton.caption) as string) width:264 height:40
 (
 	button btn_Rename "Rename" pos:[200,8] width:53 height:24
 	editText newName "" pos:[0,9] width:195 height:23
 	
 	on btn_Rename pressed do
 	(		
 		if newName.text != "" do -- if input field is not empty
 		(
 			-- write new name to ini file
 			setINISetting ini_file_path "ButtonNames" "magicButton" (newName.text as string)
 			
 			-- rename butoon caption in main rollout
 			rl_testRollout.btn_magicButton.caption = (newName.text as string)
 			
 			-- close rename rollout
 			try(destroydialog rl_renameMagicButton)catch()
 		)
 	)
 )
 

Here you can downloadfolder with script and ini file just unzip it to Scripts folder

5 Replies
(@denist)
Joined: 11 months ago

Posts: 0

that’s a right idea but the wrong implementation. we’ve discussed on this forum the way of using globals. all the same can be and must be done in the local scope.

(@deanpunchard)
Joined: 10 months ago

Posts: 0

OK I have the script working, and understand it so I can expand it to fit my script now.

Can you elaborate in simple terms please? Will I run into problems?

Thanks,

Dean

(@denist)
Joined: 11 months ago

Posts: 0

the same idea as Arahnoid’s but different realization:


  try(destroyDialog buttonText) catch()
  rollout buttonText "Button Text" width:200
  (
  	local ini_file = (getdir #temp) + "\	ext_tool.ini"
  	
  	button bt1 "Button 1" width:190 pos:[5,4]
  	button bt2 "Button 2" width:190 pos:[5,28]
  	button bt3 "Button 3" width:190 pos:[5,52]
  	
  	local buttons = #(bt1, bt2, bt3)
  	
  	edittext edt width:194 pos:[0,0] visible:off
  	timer esc interval:10 active:off
  		
  	local current = bt1
  	
  	fn endRename = 
  	(
  		esc.active = off
  		
  		current.text = edt.text
  		current.visible = not (edt.visible = off)
  	)
  	fn beginRename bt = 
  	(
  		current.visible = on
  		current = bt
  		
  		edt.pos = current.pos + [0,2]
  		current.visible = not (edt.visible = on)
  		
  		edt.text = current.text
  		setfocus edt
  		
  		esc.active = on
  	)
  	on esc tick do if keyboard.escpressed do
  	(
  		edt.text = current.text
  		endRename()
  	)
  	on edt entered text do endRename()
  	
  	on bt1 rightclick do beginRename bt1
  	on bt2 rightclick do beginRename bt2
  	on bt3 rightclick do beginRename bt3
  		
  	on buttonText open do
  	(
  		if doesfileexist ini_file do 
  			for bt in buttons where hasinisetting ini_file #buttons bt.name do bt.text = getinisetting ini_file #buttons bt.name
  	)
  	on buttonText close do
  	(
  		for bt in buttons do setinisetting ini_file #buttons bt.name bt.text
  	)
  )
  createDialog buttonText
  

the idea is to not create any global variables or extra controls (rollouts for example) if you can do without them.

unfortunately the mxs editbox control has very primitive event handles, and i have to use timer to catch ESC.

(@deanpunchard)
Joined: 10 months ago

Posts: 0

WOW! I’m super impressed, and I think I have enough knowledge to cut n paste this into my script! I love the way the script automatically creates a .ini file, which was slightly worrying as getting people to place files in the correct place can be tricky at times!!

Hopefully I should have my script finished through the weekend, so will upload and show very soon!

Thank you so much denisT and Arahnoid, your help has been amazing!!

(@deanpunchard)
Joined: 10 months ago

Posts: 0

Thanks that’s really appreciated!! I’ll check it out and let you know how I get on!

Dean

denisT, this is really amazing