Problem with inserting script into float_script controller.

Problem with inserting script into float_script controller.

Anonymous
Not applicable
612 Views
1 Reply
Message 1 of 2

Problem with inserting script into float_script controller.

Anonymous
Not applicable
Hi Guys,

So I'm learning MaxScript and everything was going well until I hit a snag. I'm writing a script that automatically adds a point helper to a spline and inserts a script into the .percent property that derives the point's position on the path from the number in it's name. The ultimate objective is to drive many points along the same path with a single control. Everything works well except when I try to enter the script into the point which gives me "can't convert float" error. If I were to insert the code manually the point does exactly what I need, but if I try to do it via script it blows up. Any thoughts? Maybe one of you old hands can take a look and see if there is something obvious in my code that can resolve this?

Much thanks. Marcin

SplineName = $.name as string + "_Anchor_"

Point name:SplineName
Temp = getnodebyname SplineName
Temp.pos.controller = position_list ()
Temp.pos.controller.Available.controller = Path_Constraint ()
Temp.pos.controller.'Path Constraint'.path = $

n = EmptyModifier ()
addmodifier $ n
$.modifiers.name = "PathControl"

att_PathControl=attributes PathControl (
parameters par_PathControl rollout:rol_PathControl (
Offset type:#float UI:spn_Offset
Spacing type:#float UI:spn_Spacing
)
rollout rol_PathControl "Path Control" (
spinner spn_Offset "Offset:" type:#float
spinner spn_Spacing "Spacing:" type:#float
)
)

custAttributes.add n att_PathControl

Temp.pos.controller.'Path Constraint'.Percent.controller = float_script()
Temp.pos.controller.'Path Constraint'.Percent.controller.AddTarget "Offset" $.PathControl.PathControl
Temp.pos.controller.'Path Constraint'.Percent.controller.AddTarget "Spacing" $.PathControl.PathControl
Temp.pos.controller.'Path Constraint'.Percent.controller.AddNode "SelfNode" Temp

Temp.pos.controller.'Path Constraint'.Percent.controller.script = "Temp = (filterstring SelfNode.name \"" + Temp.name + "\")\nY = Temp as float\nY = Y * Spacing\nY = Y + Offset\nY=Y/100\n"
0 Likes
613 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
the filterstring function is not what you have to use. you are probably want to trim anchor's name to get its ID.
i'm using this method:

(
name = "Box01"
(substring name ((trimright name "0123456789").count+1) -1) as float
)

your another mistake is when you make the point (anchor) you make them all with the same name.
probably you need to add index to the name

i slightly modified your code to make it works:

delete objects
c = (Circle isselected:on)
SplineName = $.name as string + "_Anchor_"


Temp = Point name:(uniquename SplineName)
Temp.pos.controller = position_list ()
Temp.pos.controller.Available.controller = Path_Constraint ()
Temp.pos.controller.'Path Constraint'.path = $

n = EmptyModifier ()
addmodifier $ n
$.modifiers.name = "PathControl"

att_PathControl=attributes PathControl (
parameters par_PathControl rollout:rol_PathControl (
Offset type:#float animatable:on UI:spn_Offset
Spacing type:#float animatable:on UI:spn_Spacing
)
rollout rol_PathControl "Path Control" (
spinner spn_Offset "Offset:" type:#float
spinner spn_Spacing "Spacing:" type:#float
)
)

custAttributes.add n att_PathControl

Temp.pos.controller.'Path Constraint'.Percent.controller = float_script()
Temp.pos.controller.'Path Constraint'.Percent.controller.AddTarget "Offset" $.PathControl.PathControl
Temp.pos.controller.'Path Constraint'.Percent.controller.AddTarget "Spacing" $.PathControl.PathControl
Temp.pos.controller.'Path Constraint'.Percent.controller.AddNode "SelfNode" Temp

Temp.pos.controller.'Path Constraint'.Percent.controller.script = "Temp = (substring SelfNode.name ((trimright SelfNode.name \"0123456789\").count+1) -1)\nY = Temp as float\nY = Y * Spacing\nY = Y + Offset\nY=Y/100\n"
0 Likes