Notifications
Clear all

[Closed] generating variables

Hi i want to know if its possible to generate variables from a listbox
for example:

 
....
parameters somthing rollout:pepsi
(
 
spn1 type:#float ui:spn1
 
spn2 type:#float ui:spn2
 
spn3 type:#float ui:spn3
 
 
 
)
 
rollout pepsi ""
 
(
 
spinner spn1 "" range:[0,10,1] pos:[51,23]
 
spinner spn2 "" range:[0,10,1] pos:[51,38]
 
spinner spn3 "" range:[0,10,1] pos:[51,53]
.....

I want to create spinners from an array(from a listbox). The problem a have is that when i use for loop in parameters I get that the variables are not define
for example:

 .... 
local myarray=#(spin1,spin2,spin3)
 
parameters something rollout:pepsi
(
for i=1 to myarray.count do(
myarray[i] type:#float ui:spn1
 
)

i get
Undeclared variable: spn1
[color=white]I know its right, I’m not declaring the variables , so how can i take from a listbox the names and then create spinners.
I’m no sure if its clear , if you don’t understand , il try to explain it again

thanks
[/color]

6 Replies

Hey juako,

The parameters block of a custom attribute definition expects parameters to be declared. It will not dynamically create parameters from a for loop. There exists a rolloutCreator function which you could use to dynamically build a rollout with UI from a listbox, but you’d have to go to extra lengths to incorporate this into a custom attribute definition (basically you’d have to parse up a string that is a complete attribute def and redefine the old def using the new, dynamically parsed definition).

It is possible to create a sort of “managed” custom attribute definition that reacts dynamically to user input, where you can add UI elements at will and tear them off when you don’t need them (I’ve made one), but believe me when I say its a real pain in the ass (writing code that writes code)! I’d recommend thinking of a different solution to this problem… dynamic UI’s of this order are challenging to maintain.

I don want to have a dynamic listbox , I want to input the names of the spinners and then create the spinners when i hit create. To me “dynamically” in maxscript its always a pain in the ass. But i need writing a code that writes a code, i think.
here its an image of the interface

and the spinners should look like this ones in this video
http://www.fileden.com/files/2006/9/13/216784/test.rar

the idea its to make a tool that make easy the creations of this spinners for non programmers users
I create this spinners when i saw the maya´s spinners, whit some tips from members of this forum

Disculpame, I misunderstood you. Yea, looks like you’ll need to write some functions that parse up a string that will be a custom attribute definition. Here’s a function I wrote for a modifier that manages its own custom attribute, which is similar to what you’re doing. This function creates a stringstream, then parses up some code that creates the definition, then the function executes it so that it gets added to the object as a custom attribute. Ignore the parts that call to external functions or controls… this is a single function from a very large script. Those are some very nice spinners by the way


 fn createDef rolloutName theNodeIndices:#() rampName:"" =
 (
 	local newCa = stringstream ""
 	local theMod = modpanel.getcurrentobject()
 	local modIndex = (modpanel.getmodifierindex $ theMod)
 	
 	format "poseRampCa = attributes poseRampSlidersDefDoNotModify
" to:newCa
 	format "(
" to:newCa
 	format "	local currentNodePoses = #()
" to:newCa
 	format "	local poseRamperMod
" to:newCa
 	format "	
" to:newCa			
 	format "	--rollout
" to:newCa
 	format "	rollout rollout1 \"%\"
" rolloutName to:newCa
 	format "	(
" to:newCa
 	
 	if rampName != "" do writeControl 1 1 rampName theNodeIndices newCa
 	
 	format "
" to:newCa
 	format "	)
" to:newCa
 	format "	--/rollout
" to:newCa
 	format ")
" to:newCa
 	
 	seek newCa 0
 	execute newCa
 	execute ("custattributes.add $.modifiers[" + modIndex as string + "] poseRampCa")
 	--print newCa
 	addToRollout.items = #(rolloutName)
 )
   

No hay porque!
This would be my first script, but let me see if i understood your code

 
 
fn createDef rolloutName theNodeIndices:#() rampName:"" = --create a function
 
( 
 
--define variables
 
local newCa = stringstream "" --this would contain the code
 
local theMod = modpanel.getcurrentobject() -- get the currently selected modifier
 
local modIndex = (modpanel.getmodifierindex $ theMod) -- get the number of the modifier
 
 
 
--I'm not sure how it works "format" , but i think its a way to insert streams in a stringstream
 
--then go creating the code
 
format "poseRampCa = attributes poseRampSlidersDefDoNotModify
" to:newCa
 
format "(
" to:newCa
 
format "	local currentNodePoses = #()
" to:newCa
 
format "	local poseRamperMod
" to:newCa
 
format "	
" to:newCa 
 
format "	--rollout
" to:newCa
 
format "	rollout rollout1 \"%\"
" rolloutName to:newCa
 
format "	(
" to:newCa
 
-- you add an if statement to control that the rampName its not equal to empty , and then i don't know
 
if rampName != "" do writeControl 1 1 rampName theNodeIndices newCa
 
--add more things to the code
 
format "
" to:newCa
 
format "	)
" to:newCa
 
format "	--/rollout
" to:newCa
 
format ")
" to:newCa
 
 
 
seek newCa 0 -- don't know
 
execute newCa -- not shore
 
execute ("custattributes.add $.modifiers[" + modIndex as string + "] poseRampCa") -- add to modifier the codes
 
--print newCa
 
addToRollout.items = #(rolloutName)
 
)
 

I don’t know why maxscript use “” with code inside , i thought that “” was only for strings, and i’m going to search too in max script reference for the ” ,
,/” expressions
Again I’m a beginner.
thank you very much AND Thank for the comment on the spinners

MAXScript uses “” for string. You wanted a script that builds scripts. So you create a stringStream and put all the code you want to be executed into that large string. Then you execute it as if it was a file on the harddisk. Execute someString is equivalent to opening a file and evaluating it in MAXScript.

See MAXScript Reference for the topic “How To … Enhance the Morpher Modifier With Floating Controls” which uses a similar approach and is documented line by line.

means “new line”, means tabulator, ” means quote within a string. You have to use these to format your output.

Thanks Bobo great, clear explanation!!!:applause: