[Closed] Custom Attribute – Default Value ?
hello ppl,…
i’m trying to script a lag setup on a set of bone chains. the idea is to have a float script driving my bones based off a custom attribute called “Frame_Delay” on a Dummy. now in the script, i have the following code to add the custom attribite:
fn add_custom_attribute obj =
(
addmodifier obj (emptymodifier())
fra_delay = attributes delay_name -- define your attribute names
(
parameters main rollout:roTest
(
-- define a float for the offset
fra_delay type:#integer [b]default: 2 [/b]
)
rollout roTest "add_custom_attributes" -- create a rollout
(
spinner fra_delay "delay_frame:" range:[0,10,2] type:#integer
)
)
custAttributes.add (modPanel.getCurrentObject()) fra_delay
)
clearselection()
select main_dummy -- the main control
max modify mode
add_custom_attribute($)
and then i access this custom attribute in my float script , which is so :
-- now adding expressions on the point using and using custom attribute in it
select poiarr[1]
$.rotation.controller=rotation_List()
$.rotation.controller.Euler_XYZ.controller=rotation_Script()
strr=" "
strr+= "r = quat 0 0 0 1
"
strr+= "t = slidertime
"
strr+= "w1 = $Bone01_main_ctrl.modifiers[#Attribute_Holder].delay_name[#fra_delay].value
"-- name frame
$Bone01_main_ctrl.modifiers[#Attribute_Holder].delay_name.[#fra_delay].value
"
strr+= "str1 = w1 as string
"
strr+= " str = str1 + \"f\"
"
strr+= "t2 = (t - execute(str))
"
strr+= " at time t2
"
strr+= " (
"
strr+= " r = $Bone01_main_ctrl.transform.controller.Rotation
"
strr+= " )
"
strr+= " r
"
$.rotation.controller.Rotation_Script.controller.script = strr;
now the problem is , when i access the CA value, in the above float script, it always returns the attribute’s DEFAULT value…not the current value, even if i update the spinner … any ideas on this ?
has it got to do with the CA itself or my float script ?
any ideas, awaited badly…
Hi ashishdantu,
You are missing the “ui:fra_delay” portion (user interface) of the parameters deffinition of the integer, otherwize its not connected. I would rename the spinner spn_fra_delay so there is no confussion. I would not use the default value on the deffinition of the attribute, but on the spinner, as you have used it [0,10,2]. That way, if you latter decide on a 3 as default, you only need to change it in one place, instead of looking everywhere for this kind of duplicate info.
Also, I find its a good idea to assign a bezier_float or other controller to the custom attribute so you can animate later in the graph windows.
Here is the correction:
parameters main rollout:roTest
(
-- define a float for the offset
fra_delay type:#integer [b]ui:spn_fra_delay [/b]
)
rollout roTest "add_custom_attributes" -- create a rollout
(
spinner spn_fra_delay "delay_frame:" range:[0,10,2] type:#integer
)
Hope it helps,
Rafael Polit Jr.
Quito, Ecuador.
hi RafaPolit,
thanx alot man … yes, figured it out…
just like u said, the UI thing is missing n the controller is missing…
got it to work… thanx a lot… but if i run into another prob, i’ll ask u for help again…
thanx again…
Sure, any time… if I can be of help, I’m always glad to provide it. There’s many people that do the same for me and for others , that’s what’s so great about this forums.
Cheers,
Rafael Polit Jr.
Quito, Ecuador.
hi RafaPolit,
i have run into another problem. Wud be glad to hear from u regarding this :
well , i have got a box with custom attribute called ‘wire’ and sphere with rotaion list . Under rotation list there are two Euler_xyz controllers out of which one is wired to the custom attribute on box. i.e, the CA on box controls the weight of rotation controller on the sphere.
i am trying to execute this through a script… but if i use the default statement given in listner, it gives an error… asks for “SUBANIM” …i have tried finding it out but cant figure how to put it for wiring expression.
eg is below …
paramWire.connect $Box01.modifiers[#Attribute_Holder].Custom_Attributes[#wire] $Sphere01.rotation.controller[#Weight__Euler_XYZ] “wire”
– Runtime error: connect requires subAnims
what could be going wrong in here ? what does max mean it needs subAnims ?? is there any online compilation of what the general max errors might mean ?
thanx again,
I think that this is what you are looking for.
$.rotation.controller.weights[#Weight__euler_xyz]
I think that you are going to have to set unique names on the controllers in the list so that you get the one that you want though. I always do this so I have not run into it but I just tried getting the second weight with both the controllers in the list named the same thing and I didn’t see a way of going about it.
respected Paul,
thanx a ton… just the addition of ‘s’ in wieghts made it work… for when the items in the controller is 1, it has to be ‘weight’ and if more than one, it has to be ‘weights’ …great !
thanx again,…
rgds,
ashishdantu,
Sorry I didn’t answer you before, but hollydays over here have been very time demanding this year. Sorry for that.
Good thing PEN was here for you!. As a side note, I find it easier in the learning period to enable the macro recorder in the script screen and see what the program’s code is for a specific action so I can later develop into a program. I myself use this method as I am constantly changing from other programing languages like VB, Java, C#, html, maxScritp, mel, autolisp and actionscript and often use other object referencing syntax and other lenguage specific procedures (even when the program flow is ok). This method also helps you to unveil such problems as the one you posted in the second question. Of course not everything gets into the recorder, but its a good starting place.
Regards,
Rafael Polit Jr.
Quito, Ecuador.
hi RafaPolit,
thanx for the reply n i hope u’ve njoyed ur holidays !! about my last post… yes, i’m sory i did’nt check…it in the listener… but in when i checked in the listner later, it did print ONLY > ‘WEIGHT’ not ‘WEIGHT[u][b]S’
[/b][/u]even in reference, it is mentioned as WEIGHT … no ‘s’ mentioned… so this was just a trial n error, which solved our problem. how are we to expect that english grammar is also a part of script ?? two items means plural…so use ‘s’… ? he he… anyways…
another smallll doubt i have… pls give ur valuable feedback.
i have a script which controls rotations of various dummys – something like a Follow-through setup. now in that, i have a main contol (dummy) whose rots are used for the lag.
i want to have a “ZERO OUT” button on my main control, which when clicked returns all the dummy’s back to those rotations, when they were created. n for this i added a custom attribute on the main control n added a button in that CA UI like so:
-- the main_controls's zero out string
main_ctrl_zero_Out = ("$"+main_dummy.name+".rotation.controller[1].value ="+((init_main_dummy_val)as string)+"
");
-- Adding custom attributes on the main controller
sud1 = attributes sud_name1 -- define your attribute names
(
parameters main rollout:roTest
(
-- define a float for the offset
sud1 type:#integer ui:sud1Val default: 2
)
rollout roTest "add_custom_attributes1" -- create a rollout
(
spinner sud1Val "sud1:" range:[-5,10,2] type:#integer
button btnRand "ZeroOut" -- create a button
on btnRand pressed do
(
main_ctrl_zero_Out -- string which has the quat values in it
)
)
)
the above code is a part of my setup script. My problem is, the code fails to work as the code in the ‘on btn pressed do ’ code , which now is the variable > main_ctrl_zero_Out
is’nt taken as it’s execute code.
i ‘ve tested it out with a regular UI and a button. when ever we put any variable into the ‘on pressed do’ code >> the actuall variable’s values are not given to the button… this is a BUG ??? this is very sad… we are building a button, and adding its execute commands alll through the scripts right ? so why doesnt the script substitute the variable’s contents in the on – pressed -do commands space ? this is strange…
when i put explicit lines in that space it works … eg: $bone01_main_ctrl.transform.rotation.controller[1].value= quat 95,6,5,0);
isnt there a way to make the UI ‘s execute commands to be filled dynamically ? any one, has any ideas, its much appreciated… i find max script very limited n crapy some times…
pls help…
Hi ashishdantu
You wrote your own answer, the command you are looking for is indeed the execute() command.
Just add the execute(variable_with_string_commands) line and you will be done.
on btnRand pressed do
(
execute(main_ctrl_zero_Out)
)
- You may want to add the global deffinition before the variable at declararion time.
- You don’t need the return escape code “
” at the end of the variable, remove that.
I do not believe its a crappy lengauge and by no way limited, is just a matter of figuring out the different sytaxs used (I always look for EVAL instead of EXECUTE). It takes some time, but if you are into heavy programming, maybe its worth to look at the SDK kit for programming in C++. For me, thats a bit further down the road.