ScriptSpot

Forum topic · General Scripting

Set Pivot to Minimum Z?

By Angelos · 2014-03-03

Description

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 (3)

barigazy · 2014-03-03

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

;)

barigazy · 2014-03-03

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 · 2014-03-03

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
)
)
)