UPDATED MARCH 18, 2016 – Output script information to the bottom command line after realizing there was a way to print there using Python.

select Objects with Material

One of the commands I heavily rely on aside from the much abused toggle isolate for selections is the Select Objects With Material command of the Hypershade. I usually hide/isolate stuff based on their material while modeling and unwrapping. Sometimes I even assign temporary materials to have selection sets/groups (There are better ways but it works and it became a habit, and having them on bright colors helps visually). It’s really such a convenient tool, but what I’m not a fan of is having the Hypershade open, right clicking the Material of your preference, and clicking on the command. When you work with a laptop like me, you’ll know that real estate is very precious.

In addition, I prefer to have my screen clean and minimal (in full screen mode using my own custom Marking Menu). While a friend and I were working on a build machine for our casual indie android game, he used Python and I decided to give it a try.

Anyway, the command for Selecting Objects With Material is hyperShade(objects = “”) and below is what I came up with. Basically what this does is it selects all objects with the same material as the object you selected. This works with multiple selections, so if you select, say a couple of meshes with “Metal” and “Wood” assigned to them, then all objects sharing those two materials will be selected. Now you can easily select and hide/isolate all objects with the same material with one command and without the Hypershade open. Add this to your shelf/Hotkey/Marking Menu for an easy life. Just remember to have the script on Python, not Mel.

How this works, with pictures in case you didn’t read through my novel:

STEP 1: Select an object or multiple objects. In this example, yellow was assigned for wood, magenta for metal, and cyan for leather. I selected an object with leather as well as an object with wood material.

Select Objects

STEP 2: Run script and Celebrate! Now all the materials with wood and leather are selected!

Run Script and Celebrate!

As of the March 18, 2016 update, the script outputs to the bottom command line, providing a more visible feedback.

Get feedback from the Command Line

Error feedback from the command line

5 thoughts on “Maya Python – Select Objects with Selected Object(s) Material”

  1. Can I use something like this to do an “isolate select” button? Right now you have to inculde the mesh name in order for it to work but I want to be able to grab any mesh and use the button. so it would have to check to see if there was a mesh selected then fill in the mesh name that is selected then isolate the polygons that are selected from the selected mesh. I just need to know how to how to place the select mesh information into the code of the button so that it can isolate the mesh.

    1. Hi Devin,

      I’m not sure if you replied on the wrong post, but this script selects all objects of the same material and isolates them. If you want a Toggle Isolate, you can refer to the MEL script of this old post to do isolations on your selections (https://paololazatin.com.com/toggle-isolate-selected-in-maya/). I have that one mapped to a hotkey (shift+I), but you can easily put it on your shelf/assign it to a button . None of these two actually require you to input the mesh name.

  2. Hey thats a great script, for some reason when I run it it selects everything in face mode, is there any way to make it select in objects mode so I can quickly combine the meshes ? Thank you !

    1. Hi Antoine, there was a slight typo on the script, probably when I made some changes to it some time back. Try it again now. Anyway, it should remain in object mode so long as you’ve assigned only one material per mesh. If you assign a different material to a face, it automatically switches to face mode to accommodate that face with the material. You probably have an object with two materials assigned it, so it switches to face mode. Clear this up and you should remain in object mode, and you can easily combine the meshes.

Leave a Reply

Your email address will not be published. Required fields are marked *