Set Pivot to Minimum Z?

Hi chaps

I want to find a way to create a button, so when I click it , it will the pivot of my selection to Minimum Z.

I found out that with "centerpivot selection" it takes the pivot to the center of the object.
I am looking a similar "code" that will take the pivot to minimum z.

Just to mention that I have no clue what so ever regarding scripting.

Thank you for your help!

Comments

Comment viewing options

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

...

BTW test this code and tell me if I miss something.
I always forget to check the code before I post it

;)

barigazy

barigazy's picture

...

Now U can try

-- this example works as selection.pivot.z = selection.min.z
-- and it will consider all objects as group
pivotAt selection type:#bottom asGroup:on
-- this example works as "centerpivot selection" but place pivot at the bottom
pivotAt selection type:#bottom asGroup:off
-- U can also use this fn on array of deselected nodes
-- let say we have 3 boxes in the scene that is not selected
arr = #($Box001,$Box002,$Box003)
pivotAt arr type:#bottom asGroup:on

barigazy

barigazy's picture

...

Ok U know about "centerpivot selection". Also there is the difference between
"centerpivot selection" and "selection.pivot = selection.center".
Both are mapped fn but first will consider every object separately and 2nd will consider all objects as group.
To send pivot to the bottom to every object in selection we can create simple fn.

fn valByType node mode: =
(
	local pos = node.center
	pos = case type of
	(
		#top: (pos.z = node.max.z ; pos)
		#bottom: (pos.z = node.min.z ; pos)
		#center: pos
	)
)

fn pivotAt nodes type: asGroup:on =
(
	if not asGroup then (for o in nodes do o.pivot = valByType o mode:type) else
	(
		if isKindOf nodes ObjectSet then nodes.pivot = valByType nodes mode:type else
		(
			pos = [0,0,0]
			for o in nodes do pos += (valByType nodes mode:type)/nodes.count
			for o in nodes do o.pivot = pos			
		)
	)
)

barigazy

Comment viewing options

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