Notifications
Clear all

[Closed] Adding buttons to rollout

I am new to maxscript and I am looking for a way to add a button to a rollout inside a floater once an existing button is pressed. Looking on this forum I found that a possible way would be to have pre-existing buttons set to invisible and set them to visible once the first button is pressed.
After some work I manged to get this to work properly however I would be a lot happier with my script if I managed to make it work for an unlimited number of buttons.
I also found that it´s pretty much impossible to add buttons to an existing rollout so the next best thing would be to remove the rollout, create a new one with the number of buttons being equal to the buttons on the removed rollout + 1. Although theoretically possible I have not been able to get this to work.
I have tried creating if statements and defining my own variables but none of these ideas have worked as it seems that the button creation code inside a rollout does not admit variables…or something…

Any thoughts?

7 Replies

I´ve made some progress since the previous post:

Floater = newRolloutFloater "Floater" 201 600 20 70 
  
  count = 1
  
  fn createNewRoll buttonCount Name =
  (
      newroll = rolloutCreator ("woodLib_" + (Name as string)) ("WOODS_" + (Name as string))
      newroll.begin()
      for i = 1 to buttonCount do (newroll.addControl #button ("btn_" + (i as string)) "= D") 
      newroll.addHandler ("btn_" + (buttonCount as string)) #pressed codeStr:
      "( 
          count = (count + 1)
          createNewRoll (count) (@woodLib_@ + (count as string))
          addrollout (woodLib_+count) Floater
          removerollout (woodLib_+(count-1)) Floater
      )"
      newroll.end()
  )
  
  
  rollout woodLib    "WOODS"
  (
      button button01 "= ("
  
      on button01 pressed do
      (
          count = (count + 1)
          createNewRoll (count) (count) as string
          addrollout ("woodLib_"+count as string) Floater
          removerollout woodLib Floater
      )
  )
  
  addRollout woodLib Floater

Right now I am struggling with getting the “addrollout” to recognize the custom name of the rollout when created based on a variable. Wich I am sure its a piece of cake, but my neurons ran out of fuel while finding out how to create a function =P

op…nevermind… I made it work =D

Here´s the code in case anyone finds it usefull:

 
 Floater = newRolloutFloater "Floater" 201 600 20 70 
 
 count = 1
 
 fn createNewRoll buttonCount Name =
 (
 	newroll = rolloutCreator ("roll_" + (Name as string)) ("Roll_" + (Name as string))
 	newroll.begin()
 	for i = 1 to buttonCount do (newroll.addControl #button ("btn_" + (i as string)) "= D") 
 	newroll.addHandler ("btn_" + (buttonCount as string)) #pressed codeStr:
 	"( 
 		oldroll = newroll
 		count = (count + 1)
 		createNewRoll (count) (@Roll_@ + (count as string))
 		removerollout oldroll.def Floater
 		addrollout newroll.def Floater
 		
 	)"
 	newroll.end()
 )
 
 
 rollout roll_1 "Roll_1"
 (
 	button button01 "= ("
 
 	on button01 pressed do
 	(
 		count = (count + 1)
 		createNewRoll (count) (count) as string
 		addrollout newroll.def Floater
 		removerollout roll_1 Floater
 	)
 )
 
 addRollout roll_1 Floater
 
 

This will create a floater with a rollout inside, when you hit the button in the rollout it will create a new rollout with one more button than the one before. The “create new rollout with one more button” behavior will always be included in the last button on every rollout.

Just Spent 15 mins coding this… So I’m posting although you have a solution… and it’s different techniqe…
I prefer to build them in a string stream and then execute it to define, or redefine the rollout. This allows you to preview what you are building as you go… then add the execute command and remove the print after you are happy with what is displayed in the listener…


Floater = newRolloutFloater "Floater" 201 600 20 70 
fn createNewRoll buttonCount tnName =
(
-- remove rollout
	removerollout WOOD_Rollout Floater 
-- start a string stream to build ui in
	local RollString = ( "" as stringStream )
-- define rollout
	format "rollout WOOD_Rollout \"%\" 
(
" (tnName as string) (buttonCount as string) to:RollString
-- loop and define buttons and actions
	for i = 1 to buttonCount do
		(
		format "
button btn_% \"Button #%\"
" (i as string) (i as string) to:RollString
		format "on btn_% pressed do
 (
" (i as string) to:RollString
		format " createNewRoll % %_Rollout.title
 )" (buttonCount+1) (tnName as string) to:RollString
		)
-- close rollout 
	format "
)" to:RollString
-- optional print command so you can see the structure each time in the listener 
	format "---------------
%
---------------
" (RollString as string)
-- redefine WOOD_Rollout
	execute (RollString as string )
-- add to Floater again 
	addrollout WOOD_Rollout Floater
)
 
createNewRoll 1 "Wood"
addRollout WOOD_Rollout Floater

Hope this helps…

Hehehe thanks a lot, much appriciated!..know I just have to read in the reference what the hell is a String Stream… :shrug:

Just like a fileStream, but to memory…

There are memory managment and speed advantages to the StringStream techniques over standard string functions…

(“Hi” + “There”) actually creates a third string in mem… “Hi There” and then leaves the other two floating until garbage collection happens. I believe appending is the same, but conditionally if there is enough free memory around the existing string…

String stream is just that… a stream in memory to which you write, hence it doesn’t have to look for spots to put stuff and release other things and then do a garbage collection… ect… so it’s much faster, esp in loops…

OooOOh… I see… I think… I´ve only just started scripting so I still have to get my bearings around the terms and stuff.

Anyways, thanks. I´m working on creating a (kind of) interactive material library to easily store and recycle materials from one project to another. Right now looking for materials in stored librarys from the material editor is so overly complicated that I always end up creating new materials from scratch.
I needed this button creating mechanism to be able to easily add materials to a library (click on an empty materialbutton, choose the new material, and a new button appears on the rollout with your material while the empty material button moves down).

I´ll have a look at your code and see if it´s easier to implement in that whole structure than mine. Thanks

We have smallish hand built Libs divided by usage…

Our material rollout then builds from the selected material Library. Also on each material is a Custom Attribute which holds needed mapping modifiers and maps, Vray Properties, Standard Properties, WireColor…ect…

It works well as a starting point…