Jim
Jim

Reputation: 801

Select All apart from objects with specific name in Maya using Python

I would like to select all deletable objects in my Maya scene apart from a set of Joints that start with the name JOINT_GAME

This is so that when I come to export the file, I can be sure the file is nice and clean and only contains what I need.

So far I have some code to make an array of joints to keep called 'JointsForExport'

#--- Select Joints for export then invert 

cmds.select(clear=True)
JointsForExport = cmds.ls("JOINT_GAME*")

for val in JointsForExport:
    cmds.select(val, add = True)

The next step I can't seem to work out is how to delete everything in the scene that isn't in this group

Upvotes: 1

Views: 3431

Answers (1)

DrWeeny
DrWeeny

Reputation: 2512

JointsForExport = cmds.ls("JOINT_GAME*")
all = cmds.ls()

difference = list(set(all)-set(JointsForExport))

cmds.select(difference)

Note that you shouldn't loop for select, i might be really slow :

for val in JointsForExport:
    cmds.select(val, add = True)

should be :

cmds.select(JointsForExport)

Upvotes: 1

Related Questions