def parentShape(child=None, parent=None, maintainOffset=True):
'''
Parent a child shape node to a parent transform. The child node can be a shape,
or a transform which has any number of shapes.
'''
if not child or not parent:
sel = mc.ls(sl=True)
if sel and len(sel) > 1:
child = sel[:-1]
parent = sel[-1]
else:
OpenMaya.MGlobal.displayWarning('Please make a selection.')
return
parentNodeType = mc.nodeType(parent)
if not parentNodeType in ('transform', 'joint', 'ikHandle'):
OpenMaya.MGlobal.displayWarning('Parent must be a transform node.')
return
if not isinstance(child, (list, tuple)):
child = [child]
newChild = unparentShape(child)
shapes = list()
for each in newChild:
thisChild = mc.parent(each, parent)[0]
mc.makeIdentity(thisChild, apply=True)
for s in mc.listRelatives(thisChild, shapes=True, noIntermediate=True, path=True):
shape = mc.parent(s, parent, shape=True, relative=True)[0]
#move to bottom
mc.reorder(shape, back=True)
#rename
parentName = mc.ls(parent, shortNames=True)[0]
shapes.append(mc.rename(shape, parentName+'Shape#'))
mc.delete(newChild)
for each in child:
if not mc.listRelatives(each):
#if it doesn't have any kids, delete it
mc.delete(each)
return shapes
评论列表
文章目录