Moving pivot to the bottom in python?

   2776   5   0
User Avatar
Member
85 posts
Joined: 4月 2017
Offline
Hi,

How do you guys move the pivot to the bottom of the object?
I tried to make new shelf button by modifying the python script for (Move pivot to center) shelf icon:

import toolutils

scene_viewer = None
activepane = toolutils.activePane(kwargs)
parent = activepane.pwd()
if activepane.type() != hou.paneTabType.SceneViewer:
# Use the last selected object
if parent.childTypeCategory() != hou.objNodeTypeCategory():
raise hou.Error("This tool cannot be executed in this context")
selected = [child for child in parent.children() if child.isSelected()]
else:
scene_viewer = toolutils.sceneViewer()
selected = scene_viewer.selectObjects(
prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory()),
allow_multisel = True,
allowed_types = ("geo",))

if len(selected) == 0:
raise hou.Error("Nothing was selected")

for center_obj in selected:
display = center_obj.displayNode()
if display is None:
pivot = hou.Vector3(0, 0, 0) # Use 0,0,0 by convention
else:
geo = display.geometry()
pivot = geo.boundingBox().center()
center_obj.parmTuple("p").set(pivot)

if scene_viewer is not None:
scene_viewer.setCurrentState("pose")

Tried “pivot = geo.boundingBox().center()” to “pivot = geo.boundingBox().bottom()”
but it's not working with me.

Is there other solution?

Thanks
Edited by jomaro - 2018年1月19日 08:01:39
User Avatar
Member
171 posts
Joined: 10月 2016
Offline
Hello, jomaro,
if you need to
move the pivot to the bottom of the object
you can try this
pivot = geo.boundingBox().minvec()
it will move the pivot to the bottom corner of the boundingBox.
*if your question wasn't about the center of the bottom
Edited by RyuKu - 2018年1月19日 22:39:05
User Avatar
Member
85 posts
Joined: 4月 2017
Offline
Thank you so much Ryu Ku,
My question actually was about moving the pivot to the center of the bottom but thank you that will keep me trying to understand the python more and more

Have a lovely day
User Avatar
Member
555 posts
Joined: 2月 2017
Offline
here, in the else part put this in:

    else:
        geo = display.geometry()
        pivot = geo.boundingBox().minvec()
        pivot[0]=0
        pivot[2]=0

(ie. get minvec then set x,z components to 0)

I'm not a coder so will not accept responsibility if you blow up your 'puter..
Edited by vusta - 2018年1月21日 00:48:59
User Avatar
Member
85 posts
Joined: 4月 2017
Offline
vusta
here, in the else part put this in:

    else:
        geo = display.geometry()
        pivot = geo.boundingBox().minvec()
        pivot[0]=0
        pivot[2]=0

(ie. get minvec then set x,z components to 0)

I'm not a coder so will not accept responsibility if you blow up your 'puter..

Wow, thank you so much, that's it
User Avatar
Member
85 posts
Joined: 4月 2017
Offline
vusta
here, in the else part put this in:

    else:
        geo = display.geometry()
        pivot = geo.boundingBox().minvec()
        pivot[0]=0
        pivot[2]=0

(ie. get minvec then set x,z components to 0)

I'm not a coder so will not accept responsibility if you blow up your 'puter..


This method isn't working anymore don't know why.

Anyone have a fix?
  • Quick Links