Center Pivot to Points object tool
Center the pivot of one or more objects to the center of one or more points.
||Added the Center Pivot to Points shelf tool.
# Produced by:
# Graham Thompson
# Name: object_centerpivottopoints.shelf
# Comments: Center the pivot of objects to the center of selected points.
# Version: 1.0
# Compatibility: Houdini 10.0
# Get the pane the tool was invoked in
activepane = toolutils.activePane(kwargs)
# Throw an error if it wasn't a scene viewer.
if not isinstance(activepane, hou.SceneViewer):
raise hou.OperationFailed("No scene viewer detected.")
# Select the object(s) to center the pivots to.
object_prompt = "Select the object(s) to center the pivot of and press Enter to continue."
selected_objects = activepane.selectObjects(object_prompt)
# Throw an error if nothing was selected.
if len(selected_objects) is 0:
raise hou.OperationFailed("No object was selected.")
# Clear the selection.
# Select the points to center to.
points_prompt = "Select the point(s) to center to and press Enter to complete."
geometry_selection = activepane.selectGeometry(points_prompt,
# Throw an error if no points were selected. In ordere for points to have been selected
# there must be a selected node.
if len(geometry_selection.nodes()) is 0:
raise hou.OperationFailed("No geometry was selected.")
# Get the geometry from the geometry node that was selected.
geometry = geometry_selection.nodes().geometry()
# Get a tuple of points using the point numbers from our selection.
points = geometry.globPoints(geometry_selection.mergedSelectionString())
# Calculate the center of the selected points.
position = sum((point.position() for point in points), hou.Vector3()) * (1.0 / len(points))
# For each object we selected, set the Pivot parameter to the center of our point selection.
for target in selected_objects:
# Enter the transform state.