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. On Tuesday, 17 July 2018 22:41:02 UTC+10, Rémi Deletrain wrote: > > 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()) > > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0f7f15f4-b5ce-4fe5-a8f6-6e712fe72973%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.