[Closed] creating an expression with a script??
Hello all.
I am trying to create a float_expression or a float_script with a script. I want to connect the inner amount of a shell modifier to a custom attribute (called “range” in a Custom Attribute modifier. here is what I do:
obj = $Plane02
ctrl = float_expression()
obj.modifiers[#Shell].innerAmount.controller = ctrl
ctrl.AddScalarTarget "range01" $Point01.modifiers[#Attribute_Holder].Custom_Attributes.range
the 4th line gives me the following error:
-- Runtime error: IExprCtrl::AddScalarTarget - Target needs to be controller or subAnim, got: 11.0
11.0 happens to be the current value of the “range” attribute.
Exactly the same happens when i try to create a float_script like this:
cntrl = float_script()
obj.modifiers[#Shell].innerAmount.controller = cntrl
cntrl.AddTarget "range01" $Point01.modifiers[#Attribute_Holder].Custom_Attributes.range
only to get the same error… any idea???
the expression that i try to create is :
min ((range01/length(objPos - PointAPos) + range02/length(objPos - PointBPos)),2)
however i can not create the necessary variables
Thanks
if your #range parameter is animatable you have to assign its controller using addScalarTarget, if #range is just a value you can assing it using addScalarConstant.
I’m not very sure i got what you mean but
obj = $Plane02
ctrl = float_expression()
obj.modifiers[#Shell].innerAmount.controller = ctrl
$Point01.modifiers[#Attribute_Holder].Custom_Attributes.range01.controller = Bezier_Float()
ctrl.AddscalarTarget "Range" $Point01.modifiers[#Attribute_Holder].Custom_Attributes.range01.controller
/* instead you can type it that way
ctrl.AddScalarTarget "range" ($Point01[4][1].range01.controller)
*/
the expression you want to set is not working i’m afraid … you have to give it a 2nd thought , it doesn’t even evaluate right if you put it manually
you can see this if you try to set a simpler expression
ctrl.SetExpression "min(Range,2)"
P.S
i forgot and changed the range01 to Range … keep in mind … the expression controller is Case Sensitive , and it has no clue about max objects … you have to tell it what is objpos means before you’re able to use it .
-looking at your expression again … you have to define a variable for each one of your
maxscript variables … PointAPos , PointBPos etc
Thank you guys!
cyfer, you are right, assigning the Bezier_Float() to the custom attribute was the solution! I am not sure I understand why, when i was doing it manually i didn’t have to… Is it in order to ‘say’ that the range attribute is animatable? anyway, thanks a lot!!! (the expression is working ok thought… luckily, because i couldn’t spend another 5 hours figuring that out!)
that’s little strange to hear
i thought the expression controller doesn’t know about the other variables you set in maxscript
oh, i see… no, i create all of the variables in the expression controller the same way i do for the range01. I just asked for one of them, but I used the same method for the others too… (well, the bezier_position instead of the bezier_float for the vectors…)