list.remove Maya Python

list.remove Maya Python

lemonyfreshness
Enthusiast Enthusiast
3,733 Views
1 Reply
Message 1 of 2

list.remove Maya Python

lemonyfreshness
Enthusiast
Enthusiast

list.remove function based on a string match criteria not working consistently.  Please watch the video to see what I am talking about.

 

selection = cmds.ls(selection = True)
childList = cmds.listRelatives(selection, allDescendents = True)

print('the childList is: ' + str(childList))

for eachMember in childList:
    print('eachMember is: ' + str(eachMember))
    if 'RT' in eachMember:
        print('RT found!')
        childList.remove(eachMember)
        
print('the childList is: ' + str(childList))

 

Seth Meshko
3D Artist
3danimationartist.com
0 Likes
Accepted solutions (1)
3,734 Views
1 Reply
Reply (1)
Message 2 of 2

lemonyfreshness
Enthusiast
Enthusiast
Accepted solution

Okay, I actually figured this out on my own so if anyone is interested read on!

 

I was removing entries from the list in a loop.  Removing an entry changes the layout of the loop, dropping the next entry in the list into the place of the entry I just removed.  This made it such that I was skipping over the "next" entry in the list every time I removed an entry.

I got around it by building a new list with only the entries I wanted rather than messing with the entries of the existing list.

Seth Meshko
3D Artist
3danimationartist.com