Maxscript to rotate pivot to align with edge of line

Maxscript to rotate pivot to align with edge of line

hanselmoniz
Enthusiast Enthusiast
1,447 Views
2 Replies
Message 1 of 3

Maxscript to rotate pivot to align with edge of line

hanselmoniz
Enthusiast
Enthusiast

i have got a number of individual lines (straight line with 2 points) in my scene but the pivot of the lines are not aligned to their edges. Please can anyone help me sorting this out with maxscript.

3dmaxdesign 2011 64-bit
i7 2600 windows 7 64-bit
quadro 600
0 Likes
1,448 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Is this a 2D spline or the edge of a 3D object?

2D spline...is attaching the spline to a dummy object with the right pivot an option?
0 Likes
Message 3 of 3

Anonymous
Not applicable
for o in selection do(
p = o.pos
p1 = getknotpoint o 1 1 --position of first vert on spline 1
p2 = getknotpoint o 1 2 --position of second vert on spline 2

dist = distance p1 p2
vec = p2-p1 --vector (direction of line)

ss1 = SplineShape pos:[0,0,0]
addNewSpline ss1
addKnot ss1 1 #smooth #line [0,0,0]
addKnot ss1 1 #smooth #line [0,0,dist]
updateshape ss1
ss1.dir = vec
ss1.pos = p1
o.ishidden = true
ss1.name = o.name )

This script assumes your splines only have two vertices or that the vector (rotation) you're after is the vector between vertex 1 and 2 of the spline. This doesn't rotate the pivot but it will create a new line in place of your old line.

 

If you find things are backwards, try replacing p2-p1 with p1-p2

 

Hope that helps.

0 Likes