Notifications
Clear all

[Closed] Custom Attribute – Default Value ?

hi RafaPolit,

thanx for the reply…well, s, i do have a global declaration of that variable at the beginning of my script. but when i use the execute (string) command,… it doesnt work…

the thing is, when my setup script is run, it works…soon after my script builds the button – b’se in the ‘execute (zero_out_Str)’ , the string (variable) is resident in max’s memory…so it works. but when u save n exit max and reopen the max scene , hit that button it says error : “No execute function for undefined” … i understand that ‘undefined’ here, means , max is referring to the – ‘zero_out_Str’ variable…

the button gets ’ execute (zero_out_Str) ’ embedded into its on-pressed-do code… and when max reopened, this variable is undefined ! max doesnt put those alphabets , which r there in that variable, into the execute space… it just puts > execute (zero_out_Str) , literally !

so thats where it fails… i’ve tried this execute command before… too… . you can try this on a regular rollout with a button. it does take a dynamically built string and executes it… b’se the variable declared (inside it’s execute space… ) is resident in memory n available when the button is clicked. but what happens once max is closed n reopened ?

is there a way to view or print , whats inside a button’s on-pressed-do execute statements, after it is built into an UI ? (- given the rolloout n the button name ?)

any ideas , pls ping… n i agree… till we learn all the syntax of max, its difficult. but gettting to that point itself feels a bit ” #@$^^#$%$#!@#$&*^%& ” to me… maybe its me only ? mel is easy to learn n arrive at things… anyways, waiting for ur CCs,

-rgds,

Ok ashishdantu,

I missunderstood what you where trying to do. Then you don’t need the execute() command, since the string you try to execute no longer exists later on. What you want is the script created with that variable’s string replaced in the buttons onPressed event. So what you should do is this (at least what I usually do ). Construct a string with your complete attributes definition, then execute that string assigning the result to a Variable, then add that variable to the object, as follows.:

 
-- the main_controls's zero out string 
main_ctrl_zero_Out = "$"+main_dummy.name+".rotation.controller[1].value ="+(init_main_dummy_val as string)+"
"
 
-- The Adding attributes string.
attrString = "" 
attrString += "sud1 = attributes \""+sud_name1+"\"
" -- I assume sud_name1 is a variable with a string assigned!
attrString += "(
"
attrString += "	 parameters main rollout:roTest
"
attrString += "	 (
"
attrString += "		 -- define a float for the offset
"
attrString += "		 sud1 type:#integer ui:sud1Val default: 2
" 
attrString += "	 )
"
attrString += "	 rollout roTest \"add_custom_attributes1\"
"
attrString += "	 (
"
attrString += "		spinner sud1Val \"sud1:\" range:[-5,10,2] type:#integer
"
attrString += "		button btnRand \"ZeroOut\"
"			
attrString += "		on btnRand pressed do
"
attrString += "		(
"
attrString += main_ctrl_zero_Out + "
" -- Here is the key to solving your problem			 
attrString += "		)
"	 
attrString += "	 )
"		 
attrString += ")
"
 
attrResult = execute(attrString)
objectAttributeHolder = $object_name -- Replace $object_name with the object to which the attributes will be assigned
addModifier objectAttributeHolder (EmptyModifier())
custAttributes.add objectAttributeHolder.modifiers[1] attrResult

Ok, so not the simplest way, but thats how Ive used this for a long time. This lets you do whatever you want using strings. I use this to introduce several variables into the custom attributes deffinitions as object name prefixes, sufixes, results of calculations, etc., etc. In your case, all this is needed only for the main_ctrl_zero_Out variable, but I believe it would work.

Of course it doesnt need to be formated that way, it could be a long string concatenation, but I find that its easier to see the string consturction in this way for future editing.

Give it a try, and let me know.

EDIT: In theory, you can put carriage returns directly in the same string, so this should work also:


-- the main_controls's zero out string 
main_ctrl_zero_Out = "$"+main_dummy.name+".rotation.controller[1].value ="+(init_main_dummy_val as string)+"
"
 
-- The Adding attributes string.
attrString = "" 
attrString += "sud1 = attributes \""+sud_name1+"\"
(
 parameters main rollout:roTest
 (
   -- define a float for the offset
   sud1 type:#integer ui:sud1Val default: 2
 )
 rollout roTest \"add_custom_attributes1\"
 (
  spinner sud1Val \"sud1:\" range:[-5,10,2] type:#integer
  button btnRand \"ZeroOut\"		 
  on btnRand pressed do
  (
"
attrString += main_ctrl_zero_Out + "
" -- Here is the key to solving your problem			 
attrString += ")
 )
)
"
 
attrResult = execute(attrString)
objectAttributeHolder = $object_name -- Replace $object_name with the object to which the attributes will be assigned
addModifier objectAttributeHolder (EmptyModifier())
custAttributes.add objectAttributeHolder.modifiers[1] attrResult

Rafael Polit jr.
Quito, Ecuador.

hi rafaPolit,

thanx a ton !! making the whole custom attribute thing as a string n executing it … worked …ehhooooww…

i tried this… before but i made the “on btn pressed do ( zero_out_str ) ” into a string n executed… then it gave me a rollout element missing error. didnt get the idea that the whole CA thing had to be made a string …

i’ll have to test my whole script n will inform u if it worked really…

rgds,
n thanx again, for patiently helping me out …

Page 2 / 2