0

Is there a way to preserve a parented hierarchy when duplicating and reparenting with PyMel?

I have a nested hierarchy of nodes that I want to duplicate and parent under a new group node. My selection of the top node of the hierarchy has hi=True set to ensure I have the entire hierarchy selected. But when I reparent after duplicating, the hierarchy is always lost. eg:

Duplicating this node tree |root |->branch |->leaf

Then parenting it under a new group node ("GRP") yields: GRP root branch leaf

import pymel.core as pm
root = pm.spaceLocator( n="root" )
branch = pm.spaceLocator( n="branch" )
leaf = pm.spaceLocator( n="leaf" )
pm.parent(leaf, branch)
pm.parent(branch, root)
grp  = pm.group( em=True, name='GRP' )
pm.select( clear=True )
pm.select( 'root', hi=True )
root = pm.duplicate()
pm.parent( root, grp )

TIA!

scofra
  • 3
  • 1

1 Answers1

0

Solved! Simplest solution I've found: reselect only the top node of the hierarchy before parenting; eg:

pm.select( 'root', hi=False )
pm.parent( 'root', 'grp' )
scofra
  • 3
  • 1