yeah, I brought this up. heres a custom swap script I made that validates the name.
#rename a controller with validation
def valid_rename(control, shapes):
for i, shape in enumerate(shapes):
if i == 0:
new_name = f"{control}Shape"
else:
new_name = f"{control}_{i-1}crvShape"
if not cmds.objExists(new_name):
cmds.rename(shape, new_name)
else:
cmds.warning(f"[valid_rename] {new_name} is in the scene. skipping")
#make sure the controller is correctly named
def validate_shape_names(control):
shapes = cmds.listRelatives(control, s=True) or []
valid = []
invalid = []
for shape in shapes:
single = shape == f"{control}Shape"
mgear_prefix = shape.startswith(f"{control}_") and shape.endswith("crvShape")
if single or mgear_prefix:
valid.append(shape)
else:
invalid.append(shape)
for shape in invalid:
cmds.warning(f"[validate_control] shape name invalid: {shape}. auto renaming")
if not invalid:
print(f"[valid_rename] {control} shapes are valid")
valid_rename(control, invalid)
return valid
#validate names and replace. deletes old shape. select new shape, then controller.
def replace_shapes(new_transform, target_transform):
rig_name = return_rig_name(target_transform)
valid = validate_shape_names(target_transform)
if valid:
valid_name = valid[0]
print(valid)
else:
cmds.warning("[replace_shapes] target control shapes invalid")
return
new_shape = cmds.listRelatives(new_transform, c = True, s = True)
old_shapes = cmds.listRelatives(target_transform, c = True, s = True)
for shape in new_shape:
cmds.parent(shape, target_transform, r = True, s = True)
cmds.connectAttr(f"{rig_name}.ctl_x_ray", f"{shape}.alwaysDrawOnTop")
for shape in old_shapes:
cmds.delete(shape)
renamed = cmds.rename(new_shape[0], valid_name)
cmds.delete(new_transform)