This is not exactly the answer you were hoping for, but we don't allow children under geometry here, and I think there are some good workflow reasons for that. We just use group/transforms.
R
--
You received this message because you are subscribed to the Google Groups "maya_he3d" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maya_he3d+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "maya_he3d" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/maya_he3d/aopNtPWHgj8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maya_he3d+...@googlegroups.com.
Sorry I was assuming geometry. That xsi function would be great in maya.
import maya.cmds as mc
def duplicateWithoutChildren(nodes, keepShapes=True):
if not nodes:
return []
duplicates = []
for obj in nodes:
dup = mc.duplicate(obj, rc=True)[0] # sometimes maya is buggy without renameChildren==true
# Note: The *shapes* argument can only be set to True to filter
# to only children shapes, yet it can't be set to False to False
# to return only non-shapes.
# Therefore we need to filter out all shapes ourselves (see below)
children = mc.listRelatives(dup, fullPath=True)
if children:
if keepShapes:
# Don't care about preserving order, but do care about removing
# in a fast way where one *could* possibly have many shapes.
# It's more likely a premature optimization, but `set` should
# perform much better on the cases with many many children.
# Note: We're forcing full path names (fullPath==True and long==True) in
# `listRelatives` and `ls` because we're filtering based on string names.
# This avoids any hierarchy/unique name issues. Where speed isn't critical
# but you would rather code faster give a go with Pymel.
children = list(set(children) - set(mc.ls(children, shapes=True, long=True)))
if children:
mc.delete(children)
duplicates.append(dup)
if duplicates:
mc.select(duplicates, r=1) # select newly created nodes
return duplicates
if __name__ == "__main__":
sel = mc.ls(sl=1)
duplicateWithoutChildren(sel)