Hey,
Made this tool for mirroring control shapes, which I thought would be good to share:
import pymel.core as pc
import mgear
# Store selection
selection = pc.selected()
# Define mirror direction
left_to_right = True
# Get mirror pairs from all or selection
# This could be better coded without name dependency, maybe something in mGear?
nodes = selection
if not selection:
nodes = pc.PyNode("rig_controllers_grp").members()
pairs = []
for source in nodes:
target = None
if selection:
if "_L" in source.name():
target = pc.PyNode(source.name().replace("_L", "_R"))
if "_R" in source.name():
target = pc.PyNode(source.name().replace("_R", "_L"))
if left_to_right:
if "_L" in source.name():
target = pc.PyNode(source.name().replace("_L", "_R"))
else:
if "_R" in source.name():
target = pc.PyNode(source.name().replace("_R", "_L"))
if target:
pairs.append([source, target])
# Modify control shapes
for source, target in pairs:
# Copy shapes
source_copy = pc.duplicate(source)[0]
mgear.core.attribute.setKeyableAttributes(
source_copy,
["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"]
)
# Delete children except shapes
for child in source_copy.getChildren():
if child.nodeType() != "nurbsCurve":
pc.delete(child)
# Mirror
pc.select(clear=True)
grp = pc.group(world=True)
pc.parent(source_copy, grp)
grp.scaleX.set(-1)
# Reparent, freeze transforms and match color
pc.parent(source_copy, target)
pc.makeIdentity(source_copy, apply=True, t=1, r=1, s=1, n=0)
pc.parent(source_copy, target.getParent())
mgear.core.curve.set_color(source_copy, mgear.core.curve.get_color(target))
# Replace shape
mgear.rigbits.replaceShape(source_copy, [target])
# Clean up
pc.delete(grp)
pc.delete(source_copy)
# Restore selection
pc.select(selection)
You can select a control and the script will find the mirror shape, or just let the script find all left controls and mirror across.
Its a first version of the script, so it’ll probably need some troubleshooting.