Delete the Immediate Child of a Selected Object


#1

Hi,

Whenever I do a ribbon rigging using a follicles through the Create nHair Command. There is this left out curves that I needed to delete every now and then.
See this link for illustration: https://www.dropbox.com/s/w1lj9gw2b778f26/MYA031_delete_immediate_child.jpg?dl=0

I was thinking of scripting it but due to lack of knowledge I am at impasse.

Here is what I got so far


delete listRelatives -c;

With this code I get an error of " No object matches name: listRelatives" But when I run the command without the delete, it returns the child.

Thank you for your time.


#2

1st select the hairSystem#Follicles group then execute this code


import maya.cmds as cmds
cmds.select(cmds.listRelatives(cmds.ls(selection = True), ad = True))

aFilter = cmds.itemFilter(byName='curve*')
filtered =  cmds.lsThroughFilter(aFilter,sl=True )
cmds.select(filtered)
cmds.delete(filtered)
cmds.delete(aFilter)


#3

Elvis’ solution works fine, but in case you are wondering, you can get the command you tried originally by putting marks around the listRelatives command. This basically means, delete the result of command that's getting run in between the marks.

in Mel:


delete `listRelatives -c`;

or in python:


import maya.cmds as cmds
cmds.delete(cmds.listRelatives(c=1))


#4

@greatPumpkin: thanks for the explanation !
thanks, next time I will sthatudy more


#5

@elvis75k and greatPumpkin

Thank you for the inputs! I completely forgot about the ` marks.