Parent instanciate shape with API

121 views
Skip to first unread message

Rémi Deletrain

unread,
Jul 17, 2018, 8:41:02 AM7/17/18
to Python Programming for Autodesk Maya
Hi everyone,

I try to parent an instanciate shape to new transform with API.
With command is cmds.parent(my_shape, ma_new_parent, relative=True, shape=True)

All parenting function I've found  need MObject in argument.
But with MObject it's my original shape was parented. 
It's possible to have N MDagPath for one MObject (First is path of original shape, other is instanciate object). But I don't found solution for reparent instanciate shape....

If any have solution...

Here is my code:

# Duplicate shape
mfn_shape = OpenMaya.MFnDagNode(mo_node)
mo_duplicate = mfn_shape.duplicate(True, False)

# Retrieve shape.
# When duplicate shape, new parent is created and is returned by duplicate function
mfn_duplicate = OpenMaya.MFnDagNode(mo_duplicate)
dp_duplicate = OpenMaya.MDagPath()
mfn_duplicate.getPath(dp_duplicate)
dp_duplicate.extendToShape()
# print dp_duplicate.fullPathName() # Here long path is valid

# Reparent
dp_duplicate.node() give original shape not new shape instance
mfn_parent = OpenMaya.MFnDagNode(mo_parent)
mfn_parent.addChild(dp_duplicate.node())


Michael Boon

unread,
Jul 18, 2018, 11:57:06 PM7/18/18
to Python Programming for Autodesk Maya
I've never done this, but...

Looking at your code I would say that the problem is that mo_duplicate is a MObject, which doesn't distinguish between the original and new instances. When you get an MDagPath for it, it uses the original instance by default. I guess you would need to use MDagPath.getAllPathsTo and figure out which is the new instance.

However, I think the closest equivalent of cmds.parent would be MFnDagNode.addChild(keepExistingParents=True), and it looks like that would more easily distinguish between the original and new instances. That might be an easier way to go.

Rémi Deletrain

unread,
Jul 19, 2018, 3:33:20 AM7/19/18
to Python Programming for Autodesk Maya
In my case I duplicate a nurbsCurve so OpenMaya.MFnDagNode.duplicate return a new transform with shape instanced. New transform isn't an instance.
I tryed many solution for retrieve shape but with addChild nothing works...
I just try with keepExistingParents  and.... it's the solution !!! This parameter isn't very explicit... :)

Thank you very mush Micheal !
Reply all
Reply to author
Forward
0 new messages