Command or script for aligning pivot x-axis along a 2-point-spline with different z-coordinates

Command or script for aligning pivot x-axis along a 2-point-spline with different z-coordinates

3d-labor
Collaborator Collaborator
1,207 Views
4 Replies
Message 1 of 5

Command or script for aligning pivot x-axis along a 2-point-spline with different z-coordinates

3d-labor
Collaborator
Collaborator

I searched for a long time because I was sure that it must be an easy problem. I have hundreds of lines generated by the "Glue" script of Itoosoft (wrap elements onto a surface). Sadly the pivot points remains in the position of the original lines. So I want an easy tool to align the x-axis of the pivot point along the new generated line between the two vertices which I can use on multiple lines at once. I need it to later distribute some xref-objects with the "Clone and Align" tool of 3dsmax. I found some scripts but none which does it correct. The script "scriptedglue" which is similar to "glue" move the pivot point correctly but it moves the x- and y-coordinates a little bit. So I can´t use this for my project. Any suggestions?


Workstation: Ryzen 9 5950x@ 4,20GHz 64 GB RAM, Nvidia RTX 4090, Win11 Prof. 24H2
Rendernode: AMD Threadripper 2990wx@ 3,20 GHz 64 GB RAM, Win 10 Prof.
Autodesk AutoCAD 2026, Revit 2026.1, 3dsMAX 2026.2, VRay 7, ForestPack, RailClone, KStudio ProjectManager, Miauu´s Tools....
0 Likes
1,208 Views
4 Replies
Replies (4)
Message 2 of 5

leeminardi
Mentor
Mentor

Here's a modified version of a script I wrote some time ago.  It will reposition the pivot of selected splines to the first vertex of the spline with the Z axis pointing in the direction of the second vertex.

 

Is this what you want except that the X axis should point to the second vertex?

-- changes the pivot of selected lines and splines so that the local
-- z axis is collinear with the line's first two vertices and is located 
-- at the first vertex of the line.
-- L. Minardi  6/2/2021  v3
-- 
for spl in selection where classof spl == line do (
s=1
e1 = getKnotPoint spl s 1 
e2 = getKnotPoint spl s 2
vu = normalize(e2-e1)  -- unit vector from vertex 1 to 2
m = spl.transform  -- spline matrix
ftm = translate (matrixfromnormal vu) e1
itm = ftm*(inverse m)
spl.transform = ftm
spl.objectOffsetPos *= inverse itm
spl.objectOffsetRot *= inverse itm.rotation
spl.transform
)

 

lee.minardi
0 Likes
Message 3 of 5

3d-labor
Collaborator
Collaborator

Yes, indeed. Only with the x-axis pointing to the second point. It would be perfect if then the pivot would move to the half of the line. I´m sadly not able to program it myself, I have to learn it. I have only programmed some simple autoLISP routines in the past..


Workstation: Ryzen 9 5950x@ 4,20GHz 64 GB RAM, Nvidia RTX 4090, Win11 Prof. 24H2
Rendernode: AMD Threadripper 2990wx@ 3,20 GHz 64 GB RAM, Win 10 Prof.
Autodesk AutoCAD 2026, Revit 2026.1, 3dsMAX 2026.2, VRay 7, ForestPack, RailClone, KStudio ProjectManager, Miauu´s Tools....
0 Likes
Message 4 of 5

leeminardi
Mentor
Mentor

I wanted to use rotateY to reorient the matrix so that the x axis would point in the direction of z but it didn't do what I wanted.  Luckily I could fudge an appropriate matrix by replacing the x vector with z and using a cross product to calculate a new z.  Unorthodox but it works! 

 

-- changes the pivot of selected lines and splines so that the local
-- X axis is collinear with the line's first two vertices and is located 
-- at the midpoint of the line.
-- L. Minardi  6/2/2021  v4
-- 
for spl in selection where classof spl == line do (
s=1
e1 = getKnotPoint spl s 1 
e2 = getKnotPoint spl s 2
emid = 	((e1 + e2)/ 2.)
vu = normalize(e2-e1)  -- unit vector from vertex 1 to 2
m = spl.transform  -- spline matrix
mm = MatrixFromNormal(vu)
-- rotate matrix by 90° about Y
mm.row1 = mm.row3
mm.row3 = cross mm.row1 mm.row2
ftm = translate mm emid
itm = ftm*(inverse m)
spl.transform = ftm
spl.objectOffsetPos *= inverse itm
spl.objectOffsetRot *= inverse itm.rotation
spl.transform 
)
lee.minardi
0 Likes
Message 5 of 5

3d-labor
Collaborator
Collaborator

Awesome, my friend! Thank you very much.


Workstation: Ryzen 9 5950x@ 4,20GHz 64 GB RAM, Nvidia RTX 4090, Win11 Prof. 24H2
Rendernode: AMD Threadripper 2990wx@ 3,20 GHz 64 GB RAM, Win 10 Prof.
Autodesk AutoCAD 2026, Revit 2026.1, 3dsMAX 2026.2, VRay 7, ForestPack, RailClone, KStudio ProjectManager, Miauu´s Tools....
0 Likes