Duplicate an object and rename the constraint it contains

Duplicate an object and rename the constraint it contains

dg3duy
Collaborator Collaborator
573 Views
2 Replies
Message 1 of 3

Duplicate an object and rename the constraint it contains

dg3duy
Collaborator
Collaborator

I can now duplicate the selected camera, but I cannot rename the constraint it contains with an _UE extension.

import maya.cmds as cmds

# Select the camera
camera = cmds.ls(selection=True)[0]

# Creates a copy of the original camera and gives it a name with the ending "_UE".
camera_copy = cmds.duplicate(camera, name=camera+"_UE")[0]

rename constraint.gif I hope you can give me some help in this matter, it has not been easy for me so far, thank you very much.

0 Likes
Accepted solutions (1)
574 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

You just have to find the parentconstraint by using listRelatives and rename it after the fact.

Also if you want the parentconstraint to work, you need the inputConnections (ic) flag in the duplicate command to be set to True, otherwise the constraint will not be connected to the parent nodes.

import maya.cmds as cmds

# Select the camera
camera = cmds.ls(selection=True)[0]

# Creates a copy of the original camera and gives it a name with the ending "_UE".
camera_copy = cmds.duplicate(camera, name=camera+"_UE", ic = True)[0]
constraint = cmds.listRelatives(camera_copy,c= True, type ="parentConstraint", pa= True)[0]
cmds.rename(constraint,camera_copy[:-3] + "_parentConstraint_UE")

 

I hope it helps!

Message 3 of 3

dg3duy
Collaborator
Collaborator

Excellent, thank you very much, it works great.

0 Likes