[Closed] Help with path constraint
Hi there,
I did some search over at scriptspot but couldn´t find exactly what I need:
I have an object and have it path constraint to a spline. The percentage is an animated loop.
Now I want to instance that object inkluding its animation along the spline.
I wanna set a number of clones and the percentage for the offset (for example: each instance should be 0.65 % further away from the last object).
I just can´t find the time to properly learn maxscript, so I´d appreciate some help…I hate it, that everytime I start looking for a scripted solution, after a few hours without success fumbling around with mascscript I end up doing it all manually again…
Well, I guessed a temporary solution:
A=$selection
instance A
for i in selection do
(
i.position.controller.percent = (i.position.controller.percent) - 0.65
)
Now all I have to do is to hit “CTRL+E” as often and fast as I can…
Your code doesn’t appear to change the percent value of each instance. Which version of Max are you running?
Perhaps this will help:
A=getCurrentSelection()
Copies = 10
for i = 1 to Copies do
(
B = instance A[1]
B.pos.controller.Path_Constraint.controller.percent -= 0.65 --ignor the space in percent, the forum code tags keep adding it
A = #(B)
)
obj =$ --the main constrainted object
mysel = for k=0 to 10 collect ( instance obj )
/*
--if you have created your objects
obj = $ --the main constrainted object
--select the instanced objects
mysel = selection as array
*/
objPercent = obj.pos.controller.Path_Constraint.controller.percent
mypercent = 0.65 --or any number
for i in 1 to mysel.count do
(
j = mysel[i]
j.pos.controller.Path_Constraint.controller.percent = objPercent+mypercent*i
)
some time it put blanks in some words it is percent not perc ent
not a big fan of the “auto” keyframing on path constraints, keyframes can be tricky to manage when the system gets complicated so this is how I would handle it.
(
fn CreatePathConstrait_withoutKeys thePath loop =
(
pcon = Path_Constraint();
pcon.path = thePath;
pcon.percent = 0;
pcon.percent.controller = float_expression();
pcon.loop = loop ;
pcon.constantVel = true; -- make evenly spaced
pcon.follow = true;
deleteKeys pcon #allkeys;
pcon;
)
fn CreateHelper thePath loop =
(
new_helper = Point size:10 cross:on axistripod:off
new_helper.name = uniqueName "pfollower"
new_helper.position.controller = CreatePathConstrait_withoutKeys thePath loop
new_helper
)
fn Create_The_System theRotator thePath num_helpers multiplier loop offset =
(
base_percent = 100.0/num_helpers;
for i = 1 to num_helpers do
(
position_helper = CreateHelper thePath loop
start_percent = 100 - ((i - 1) * base_percent) + offset
fexpr = ("(" + (start_percent/100) as string + " - radToDeg(-rotation)/360 * " + multiplier as string + ")")
fexpr_controller = position_helper.position.controller.percent.controller
target_controller = theRotator.rotation.z_rotation.controller
fexpr_controller.IExprCtrl.AddScalarTarget "rotation" target_controller Offset:0t
fexpr_controller.IExprCtrl.SetExpression fexpr
)
)
clearlistener();
delete objects;
thePath = Circle radius:100 pos:[0,0,0] name:"thepath";
rotator = point size:20 cross:off axistripod:on isSelected:on name:"therotator";
Create_The_System rotator thePath 16.0 0.5 true 0.0;
)
each helper is added to the “system” where it’s path percentage is controlled by the z rotation of the rotator helper with the help of an expression controller on path constraint percent controller.
i would do it this way:
fn placeAlongPath node path count gap: loop:off =
(
if gap == unsupplied do gap = if loop then 100.0/count else 100.0/(count-1)
node.position.controller = createinstance path_constraint path:path percent:0 loop:loop
nodes = #(node)
for k=2 to count do
(
maxOps.CloneNodes node cloneType:#instance newNodes:&new
new[1].pos.controller.percent = (k-1) * gap
join nodes new
)
#(nodes, path)
)
/** examples **/
delete objects
placeAlongPath (point size:2 wirecolor:yellow) (circle radius:10 wirecolor:green) 16 loop:on
sp = line wirecolor:orange
addnewspline sp
addknot sp 1 #corner #line [0,0,0]
addknot sp 1 #corner #line [0,50,0]
placeAlongPath (point size:3 wirecolor:red) sp 20 loop:off
hi guys,
thanks for chiming in, since my code snippet did what I needed (I´m on Max 2015 by the way), I already moved on. But since this is something I have to do quite often, I´ll look into your suggestions and let you know how they work out for me!
I love it that there always multiple solution to achieve almost everything in max…