How to select faces by Its Material?

How to select faces by Its Material?

Anonymous
Not applicable
37,771 Views
8 Replies
Message 1 of 9

How to select faces by Its Material?

Anonymous
Not applicable

Is there a way I can select all the faces which are assigned to a certain material?

0 Likes
Accepted solutions (1)
37,772 Views
8 Replies
Replies (8)
Message 2 of 9

J450NP13
Advisor
Advisor
Accepted solution

Go into the hypershader and right click on a shader and select select objects by material.

Message 3 of 9

jewboy0117
Enthusiast
Enthusiast

this is not an answer to selecting faces, only objects with said materials. If you have an object with multiple materials then this can be a problem. 

Message 4 of 9

Anonymous
Not applicable

If you follow the steps above, you can selected faces with different materials in the same object. 

0 Likes
Message 5 of 9

Climber_FX
Contributor
Contributor

The problem is only when you want to select the faces of only one of many objects that have this particular shader between many others. If you have one object with multi materials, it select only the faces with your choice on the object.

Message 6 of 9

Christoph_Schaedl
Mentor
Mentor

Use this Python script.

 

import maya.cmds as mc
# select object or face
b = mc.ls(sl=1)[0].split("[")[0] # remember a token for comparison below
mc.hyperShade(smn=1) # that will select the shader
s = mc.ls(sl=1)[0] # remember the selected shader
sg = mc.listConnections(s+".oc", s=0, d=1)[0] # figure out the shading group
# select the faces of the same object with same shader attached
l = []
for o in mc.sets(sg, q=1):
    if b not in o: continue
    l.append(o)
mc.select(l)
----------------------------------------------------------------
https://linktr.ee/cg_oglu
Message 7 of 9

andymc4997
Advocate
Advocate

Hi, I really need this script to work, as I have multiple objects which have multiple shaders assigned. However, I'm receiving this error for a given material:

 

Error: ValueError: file <maya console> line 6: No object matches name: Metal.oc

 

"Metal" is the shader I'm trying to switch out with a different one on my selected object. Can this be fixed?

 

My specs:

 

Maya '20

Win10 64bit

 

Thanks so much in advance.

Message 8 of 9

kopacabana
Participant
Participant

Hi Andy,

 

If you need to select another shader, specify the index (change 0 by another index) :

s = mc.ls(sl=1)[0]

 

For the ".oc" problem, replace :

sg = mc.listConnections(s+".oc", s=0, d=1)[0]
with :
sg = mc.listConnections(s, s=0, d=1)[0]
0 Likes
Message 9 of 9

Anonymous
Not applicable
sux
0 Likes