Centering Pivot Point to World Origin for Selected Objects with Maya Python3 Script

Tutorial / 25 October 2023

The script's purpose is to manipulate the pivot point of selected objects in the 3D workspace. It only works with Maya.

The function, center_pivot_to_world_origin(), operates on the currently selected objects in the Maya scene. It sets the pivot point of each selected object to the world origin, which is the point (0,0,0) in the 3D space.

The function first retrieves the list of currently selected objects using the cmds.ls(selection=True) command. It then iterates over each selected object, and for each one, it sets the pivot point to the world origin (0,0,0) using the cmds.xform(obj, pivots=world_origin, worldSpace=True) command.

The worldSpace=True argument ensures that the pivot point is set in world space, not in the object's local space.

This script is useful when you want to align the pivot points of multiple objects to a common point in the 3D space, such as the world origin. This can be helpful in various 3D modeling and animation tasks, such as preparing objects for rigging, or aligning objects for a group operation.

import maya.cmds as cmds


def center_pivot_to_world_origin():
    # Get the currently selected objects
    selection = cmds.ls(selection=True)


    # Define the world origin
    world_origin = [0, 0, 0]


    # Loop through each selected object
    for obj in selection:
        # Set the pivot point to the world origin
        cmds.xform(obj, pivots=world_origin, worldSpace=True)


# Call the function
center_pivot_to_world_origin()

Please note that the script assumes that you have at least one object selected in Maya. If no objects are selected, the cmds.ls(selection=True) call will return an empty list, and the loop will not execute. If you want the script to handle the case where no objects are selected, you could add a check at the beginning of the function to see if any objects are selected, and if not, print a message and return early.