Rotate Pivot Z to orientation of largest face

Hey everyone, is it Possible to rotate the Pivot Z-axis to the Largest Face of an object, like in the example in the picture?
It should find the largest face by his own, no manual selection.

Thx

AttachmentSize
pivots.jpg399.67 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

Try this:

(
	local poGetNumFaces = polyop.getNumFaces
	local poGetFaceArea = polyop.getFaceArea 
	local poGetFaceCenter = polyop.getFaceCenter
	local poGetFaceNormal = polyop.getFaceNormal
 
	function AlignPivotToFace obj face  = 
	(
		c = poGetFaceCenter obj face
		n = poGetFaceNormal obj face
		ftm = translate (matrixfromnormal n) c	
		itm = ftm*(inverse obj.transform)
		obj.transform = ftm
		obj.objectOffsetPos *= inverse itm
		obj.objectOffsetRot *= inverse itm.rotation
		obj.transform
	)	
 
	selObjsArr = selection as array
	if selObjsArr.count != 0 do
	(
		for o in selObjsArr where classOf o == Editable_Poly do
		(
			numFaces = poGetNumFaces o
			maxArea = -1
			largestFaceIdx = 0
			for f = 1 to numFaces do
			(
				fArea = poGetFaceArea o f
				if fArea > maxArea do
				(
					largestFaceIdx = f
					maxArea = fArea
				)
			)
			if largestFaceIdx != 0 do
			(
				AlignPivotToFace o largestFaceIdx
			)
		)
	)
)

Works only with Editable Poly object and if you have two more more faces with the same area the script will align the pivot to last larger face it finds.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.