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
Solved! Go to Solution.
Solved by kenc. Go to Solution.
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.
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.
@denisT.MaxDoctor no FBX. Also has 3ds which is no good all the meshes are called "Mesh". Checking DWG now
What happens when you use Akign to object?
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?
@leeminardi this needs to be run by maxscript. No user input.
The Align To Object does not work
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.
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.
@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.
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)
)
@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?
Sorry I should have been more specific. Rotate the pivot with maxscript.
Everything I do is by maxscript only.
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.
@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 😉