PDA

View Full Version : Adding buttons to rollout


MarcoBrunetta
02-15-2008, 12:26 PM
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 its 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?

MarcoBrunetta
02-15-2008, 03:43 PM
Ive 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

MarcoBrunetta
02-15-2008, 04:29 PM
op...nevermind... I made it work =D

Heres 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.

Kramsurfer
02-15-2008, 05:35 PM
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 \"%\" \n(\n" (tnName as string) (buttonCount as string) to:RollString
-- loop and define buttons and actions
for i = 1 to buttonCount do
(
format "\nbutton btn_% \"Button #%\"\n" (i as string) (i as string) to:RollString
format "on btn_% pressed do\n (\n" (i as string) to:RollString
format " createNewRoll % %_Rollout.title\n )" (buttonCount+1) (tnName as string) to:RollString
)
-- close rollout
format "\n)" to:RollString
-- optional print command so you can see the structure each time in the listener
format "---------------\n%\n---------------\n" (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...

MarcoBrunetta
02-15-2008, 05:42 PM
Hehehe thanks a lot, much appriciated!...know I just have to read in the reference what the hell is a String Stream... :shrug:

Kramsurfer
02-15-2008, 05:51 PM
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....

MarcoBrunetta
02-15-2008, 06:20 PM
OooOOh... I see....... I think... Ive only just started scripting so I still have to get my bearings around the terms and stuff.

Anyways, thanks. Im 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).

Ill have a look at your code and see if its easier to implement in that whole structure than mine. Thanks

Kramsurfer
02-15-2008, 11:36 PM
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...

CGTalk Moderation
02-15-2008, 11:36 PM
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.