Skip to main content

convert_to_joint_to_null_obj

I usually do RND rigging through joints. The controls are baked into the joints but when shipping the rig, I usually need to separate the joints and the controls.

And on of those process is using the joints pivot as the basis to the controls. The script converts the joints to null objects. Does not take into account the hierarchy though.

import pymel.core as pm

def convert_joint_to_transform(joint_obj):
# Check if the provided joint exists and is of type 'joint'
# joint = pm.PyNode(joint_name)
# if not joint.exists() or not isinstance(joint, pm.nt.Joint):
# raise ValueError(f"Joint '{joint_name}' does not exist or is not of type 'joint'.")

#joint_obj = pm.PyNode(joint_name)

# Create a new transform node
#transform = pm.createNode('transform', name=joint_name.getName() + '_con')
circle_curve, _ = pm.circle(name=joint_obj.getName().split("_jnt")[0] + '_con', normal=[1, 0, 0], radius=1)

transform = circle_curve

# Get the transformation attributes from the joint and apply them to the new transform node
transform.setMatrix(joint_obj.getMatrix(worldSpace=True), worldSpace=True)

# Find the shape node of the joint (if any)

new_joint = pm.instance(joint_obj)[0]
shapes = new_joint.getShapes()

if shapes:
for shape in shapes:
# Reparent the shape node to the new transform node

# new_shape = pm.instance(shape)[0]
# joint.getShapes()
pm.parent(shape, transform, shape=True, relative=True)
# Rename the shape node
#new_shape.rename(joint.getName() + '_shape')

# Optionally delete the original joint
pm.delete(new_joint)

#print(f"Joint '{joint_name}' converted to transform node '{transform}' with shape node '{shape}'.")

# Example usage
obj_sel = pm.ls(sl=True)

for obj in obj_sel:
convert_joint_to_transform(obj)
import pymel.core as pm

def convert_joint_to_transform(joint_obj):
# Check if the provided joint exists and is of type 'joint'
# joint = pm.PyNode(joint_name)
# if not joint.exists() or not isinstance(joint, pm.nt.Joint):
# raise ValueError(f"Joint '{joint_name}' does not exist or is not of type 'joint'.")

#joint_obj = pm.PyNode(joint_name)

# Create a new transform node
#transform = pm.createNode('transform', name=joint_name.getName() + '_con')
circle_curve, _ = pm.circle(name=joint_obj.getName().split("_jnt")[0] + '_con', normal=[1, 0, 0], radius=1)

transform = circle_curve

# Get the transformation attributes from the joint and apply them to the new transform node
transform.setMatrix(joint_obj.getMatrix(worldSpace=True), worldSpace=True)

# Find the shape node of the joint (if any)

new_joint = pm.instance(joint_obj)[0]
shapes = new_joint.getShapes()

if shapes:
for shape in shapes:
# Reparent the shape node to the new transform node

# new_shape = pm.instance(shape)[0]
# joint.getShapes()
pm.parent(shape, transform, shape=True, relative=True)
# Rename the shape node
#new_shape.rename(joint.getName() + '_shape')

# Optionally delete the original joint
pm.delete(new_joint)

#print(f"Joint '{joint_name}' converted to transform node '{transform}' with shape node '{shape}'.")

# Example usage
obj_sel = pm.ls(sl=True)

for obj in obj_sel:
convert_joint_to_transform(obj)