Select By Material – Python Snippet

posted in: Uncategorized | 0

Here’s another one-line snippet that selects all faces and objects in a scene based on shading group set. Material assignment in Maya is driven by “sets”. According to the Maya documentation, “a set is a logical grouping of an arbitrary collection of objects, attributes, or components of object.”  We’ll be querying a set to find everything assigned by a specific material and then selecting it."initialShadingGroup", q=True))

This line selects faces and objects assigned with lambert1, a helpful check I perform in scenes before exporting. (We never want artists to export default Maya materials.) It shows the artist where in the scene the lambert1 lives by highlighting it in the selection.

If you don’t know the name of the set associated with the material off hand (you probably won’t), you can easily translate from material name to set:

materialName = "lambert1"
shadingGroup = cmds.listConnections(materialName, type="shadingEngine")
componentsWithMaterial = cmds.sets(shadingGroup, q=True)


Leave a Reply