Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Align object's pivot to object's orientation

60 REPLIES 60
SOLVED
Reply
Message 1 of 61
kenc
2871 Views, 60 Replies

Align object's pivot to object's orientation

I have a DXF from Softplan that I import into max. When the objects come in they all have the same pivot rotation orientation. I then center the pivots to each object's center as seen in image1.jpg

 

What I need to do is by maxscript is to align the object's pivot to the object's orientation. In image2.jpg the pivot for an object does not align with the object but rather at 45 degrees.

 

In image3.jpg this is how I need to rotate the pivot to align with the object.

 

Help would be much appreciated.

 

TIA

60 REPLIES 60
Message 2 of 61
denisT.MaxDoctor
in reply to: kenc

Is only DXF format available for export from Softplan? 
If we are talking about AutoCAD DXF, there should be no problem with pivot (tm) orientation.

 

Message 3 of 61
kenc
in reply to: kenc

it is exported directly from softplan. I just asked the cad guys to export to 3ds and fbx

Message 4 of 61
denisT.MaxDoctor
in reply to: kenc

Usually, the "oriented bounding box" method is used to solve this problem. As far as I know, there is no built-in solution for this, but I remember some scripts to do the job.

 

For 2D case, the script is quite simple.

Message 5 of 61
denisT.MaxDoctor
in reply to: kenc

What other formats the Softplan can export? Can it do FBX?

Message 6 of 61
kenc
in reply to: kenc

@denisT.MaxDoctor  no FBX. Also has 3ds which is no good all the meshes are called "Mesh". Checking DWG now

 

Message 7 of 61
kenc
in reply to: kenc

@denisT.MaxDoctor DWG and DXF output exactly the same thing

 

Message 8 of 61
leeminardi
in reply to: kenc

What happens when you use Akign to object?

leeminardi_0-1711145622922.png

 

Are the object composed  of lines or 2d, or 3D objects.

 

A simple script could be used that prompts the user to specify a pivot origin, a point on the x axis, and a point on the xy plane and then reorient the pivot and center it.   Would this be acceptable?

 

 

lee.minardi
Message 9 of 61
kenc
in reply to: leeminardi

@leeminardi this needs to be run by maxscript. No user input.

The Align To Object does not work

Message 10 of 61
leeminardi
in reply to: kenc

Can you post a sample dxf file?

 

lee.minardi
Message 11 of 61
klvnk
in reply to: kenc

getting a tight object aligned bounding box and therefore it's "orientation"/pivot for all general cases is a non trivial operation. Though in special cases it maybe easier.

Message 12 of 61
istan
in reply to: klvnk


@klvnk wrote:

Though in special cases it maybe easier.


In this particular case, when objects always look like in image1 (a "thin" object), at least one vector could be easily aligned per MXS.

Message 13 of 61
leeminardi
in reply to: istan

It looks like the application is related to cabinetry and therefore the pivot Z axis is correct.  So yes, only one vector is needed to define orientation.  A sample file would be helpful. Searching for consecutive vertices that have the same z coordinate may be sufficient to determine the vector.

lee.minardi
Message 14 of 61
kenc
in reply to: kenc

@leeminardi actually it's an entire house. The items in my screenshots are the kitchen cabinets.

I'm not at the office but I will remote in and get the dxf.

Message 15 of 61
leeminardi
in reply to: kenc

I created a couple of "panels" (boxes) in AutoCAD and determined that the first two vertices could be used to define the orientation of the pivot.

Try the following program and let me know how it works on your file.

-- Modifies selected object pivots such that their
-- first two vertices define the local x axis and
-- the local z axis is in the world z axis direction.
obj = selection
for o in obj do 
(
v1 = getVert o 1
v2 = getVert o 2
xaxis = normalize(v2 - v1)
yaxis = normalize(cross [0,0,1] xaxis)
a = acos(dot [1,0,0] yaxis)
o.transform = o.transform * (RotateZMatrix a)
resetxform o
maxOps.CollapseNodeTo o 1 true
o.transform = o.transform * (RotateZMatrix -a)
)

 

lee.minardi
Message 16 of 61
kenc
in reply to: kenc

@leeminardi apparently all our servers are under maintenance this weekend so I can't upload the dxf till Monday.

 

I will try out your script.

 

How do I rotate just the pivot of an object without rotating the object?

Message 17 of 61
leeminardi
in reply to: kenc


@kenc wrote:

 

How do I rotate just the pivot of an object without rotating the object?


leeminardi_0-1711226262004.png

 

lee.minardi
Message 18 of 61
kenc
in reply to: leeminardi

Sorry I should have been more specific. Rotate the pivot with maxscript.

Everything I do is by maxscript only.

Message 19 of 61
leeminardi
in reply to: kenc

I do it by rotating the object orthogonal to the world reset the transform and rotate the object back.

Take a look at my code.

[Edit]

Since in your case we just need to rotate about the z axis we can use a z-axis matrix rotation. If the rotation were more complex you would have to use quats.

lee.minardi
Message 20 of 61
istan
in reply to: leeminardi


@leeminardi wrote:

 If the rotation were more complex you would have to use quats.


Remark: there's no need to use quats, if you would omit using angle values in your calculation.. there exists another solution using simple matrix calculations 😉

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report