Align object's pivot to object's orientation

Align object's pivot to object's orientation

kenc
Advocate Advocate
9,265 Views
60 Replies
Message 1 of 61

Align object's pivot to object's orientation

kenc
Advocate
Advocate

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

0 Likes
Accepted solutions (3)
9,266 Views
60 Replies
Replies (60)
Message 41 of 61

denisT.MaxDoctor
Advisor
Advisor

Could you post an example scene in version 2020 or earlier?

 

or/and a DXF file?

0 Likes
Message 42 of 61

denisT.MaxDoctor
Advisor
Advisor

@kenc wrote:

What I do is shoot a ray 2 inches in both directions in the y-axis. If the ray strikes SURFACE then I know the pivot needs to be rotated 180 in the z-axis. I already have the code setup to detect if it needs to be rotated. I just need to rotate it now.


show the "need to rotate" code...

0 Likes
Message 43 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor max file attached as 2019. Deleted all but doors and cabinets. The pivots are pointing in the direction after I ran your last code.

My vector code doesn't work

0 Likes
Message 44 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor the pivots have to point backwards from center of door.

0 Likes
Message 45 of 61

denisT.MaxDoctor
Advisor
Advisor

@kenc wrote:

@denisT.MaxDoctor max file attached as 2019. Deleted all but doors and cabinets. The pivots are pointing in the direction after I ran your last code.

My vector code doesn't work


As I can see from the example scene, there is no simple rule for automatically finding the correct panel pivot direction.
The best I can suggest is to use a "preselected" face for each panel, specifying the pivot direction. If you specify a front face, the rotation will face forward, if you specify a back face, the rotation will face backward (as you want).

 

If the face selection method is used, the specified face no longer has to be "maximum size", which also solves the previous limitation.

fn setPivotRotation obj tm =
(
	worldAlignPivot obj
	local rot = inverse tm.rotationpart
	
	animate off in coordsys local obj.rotation *= rot
	obj.objectoffsetrot *= rot
	obj.objectoffsetpos *= rot
	obj.objecttransform
)

mapped fn alignPivotToFace obj face:#max zUp:on = if iskindof obj Editable_Mesh do
(
	fn getMaxFace obj = 
	(
		fmax = meshop.getfacearea obj 1
		i = 1
		for k = 2 to obj.numfaces where (area = meshop.getfacearea obj k) > fmax do
		(
			fmax = area
			i = k
		)
		i
	) 
	fn matrixZUp tm =
	(
		side = normalize (cross z_axis tm[3])
		front = cross z_axis side
		
		matrix3 side front z_axis tm.pos
	)
	
	if face == #max then face = getMaxFace obj
	else if face == #sel then
	(
		face = ((obj.selectedfaces as bitarray) as array)[1]
	)
	else face = int face
	
	if face != undefined and face > 0 and face < obj.numfaces do
	(
		norm = getfacenormal obj face	
		tm = matrixfromnormal norm
		
		if zUp do
		(
			tm = matrixZUp tm
		)
		
		centerPivot obj
		setPivotRotation obj tm
	)
)

alignPivotToFace selection face:#sel

 

0 Likes
Message 46 of 61

denisT.MaxDoctor
Advisor
Advisor

@denisT.MaxDoctor wrote:


The best I can suggest is to use a "preselected" face for each panel, specifying the pivot direction. If you specify a front face, the rotation will face forward, if you specify a back face, the rotation will face backward (as you want).

Yes, preparing scenes that are likely to have many "panels" will take time. However, in a properly organized process, such tasks are solved at the stage of pipeline design and tool selection, not by inventing voluntaristic rules.

0 Likes
Message 47 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor the script works but the higher powers here don't like the user intervention. Thy want it fully automated. I told them that I am stopping the R&D on this.

On a side note, I was chatting with a maxscript guru like yourself and he said he will not touch anything from SOFTPLAN because it's too complicated and it's not worth the effort.

0 Likes
Message 48 of 61

denisT.MaxDoctor
Advisor
Advisor

@kenc wrote:

@denisT.MaxDoctor the script works but the higher powers here don't like the user intervention. Thy want it fully automated. I told them that I am stopping the R&D on this.

On a side note, I was chatting with a maxscript guru like yourself and he said he will not touch anything from SOFTPLAN because it's too complicated and it's not worth the effort.


To automate this process, it is necessary to have some unambiguous rule that constantly accompanies every file and every object in it. Does such a rule exist?
I don't see it. 

0 Likes
Message 49 of 61

denisT.MaxDoctor
Advisor
Advisor

I looked in the Softplan editor and saw that you can name any object and the object name will be exported in DXF format. Create a panel and its pivot point as an additional object using a naming convention. For example, name the panel "Panel_00" and its pivot point "Panel_OO_pivot". After importing the DXF to MAX, we can find the panel and pivot by name, use their centers to determine the front direction and orient the panel's pivot in MAX unambiguously.

0 Likes
Message 50 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor we don't actually use SOFTPLAN. We receive the DXF export and we never know what we will get. Most of our work is from 2D floorplans and it is modelled directly in MAX with help of a library that we made ourselves.

 

To be honest I don't want us to get involved with another 3D package, we're using enough as it is.

0 Likes
Message 51 of 61

denisT.MaxDoctor
Advisor
Advisor

SOFTPLAN, DXF, 2D floorplans... Start with the pipeline design first. Don't waste your time. I don't really care about your time, but I don't waste mine anymore. Good luck.

0 Likes
Message 52 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor we have a pipeline for 2D plans and have for 15 years. The client sends the plans and cad dept. builds it. This is the first time we've received softplan and the boss doesn't want to spend a lot of time on it, neither do I.

0 Likes
Message 53 of 61

denisT.MaxDoctor
Advisor
Advisor

Okay... Give me one of the DXF files you're using. Don't tell me you have DNA or some sort of security issue. Try to find a way to post something very close to what you use in your work.

0 Likes
Message 54 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor the only dxf we have is for that softplan model

0 Likes
Message 55 of 61

denisT.MaxDoctor
Advisor
Advisor

@kenc wrote:

@denisT.MaxDoctor the only dxf we have is for that softplan model


post this DXF file. I need to look exactly in DXF, not MAX, not JPEG...

0 Likes
Message 56 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor here you go. It's a zip file

0 Likes
Message 57 of 61

denisT.MaxDoctor
Advisor
Advisor

@kenc wrote:

@denisT.MaxDoctor here you go. It's a zip file


As I see it, most of the panels in the Cabinet MAX file have handles (knobs)... they can be used to determine the direction of facing (rotation). The only possible solution is to ask the DXF creators (Softplan designers) to add a knob (real or fake) for each panel that needs to have a precise direction (opening, sliding, or another animation purpose...)

 

This is where the story ends. How to determine the direction from the knob is another one.

0 Likes
Message 58 of 61

kenc
Advocate
Advocate

@denisT.MaxDoctor I'm not spending anymore time on it unless the higher ups say so. They are aware of the situation.

I am going to mark your last script as a solution.

I appreciate your time and the work you did helped me a lot.

0 Likes
Message 59 of 61

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@kenc wrote:

 

I am going to mark your last script as a solution.

 


do it. let's turn this page

0 Likes
Message 60 of 61

kenc
Advocate
Advocate
Accepted solution

@denisT.MaxDoctor thank you. I'm sure we'll run into each other again down the road.

0 Likes