Selecting the connected material in Mel


#1

Hey everyone I am very new to coding and I am trying to select the surface material based off the section of the shadingEngine (shader group)


//selects all of the shading groups in the scene
string $selShaderGroups = `ls -type shadingEngine`;


the part that I am trying to figure out is how to select the material connected to each shader group. This code gets me close but also includes which geometry is connected.


string $selMaterials[] = `listConnections -d 0 -s 1 -p 0 $selShaderGroups`;



#2

my idea :
string $blinnShading[] = ls -type "blinn";
string $phongEShading[] = ls -type "phongE";
.etc…


#3

I know your ask about MEL, but since you are new to coding, it would not be a problem to switch to PyMel, because it`s obviously a better choice for Maya developing and its much easier to learn.

import pymel.core as pm
SG = pm.ls( sl = 1, type = 'shadingEngine' ) # get list of selected shading groups
material = pm.ls( pm.listConnections( SG ), materials = 1 ) # get list of connected materials inclooding displacement


You can see more examples of PyMel code related to shading and materials
If you will explain what do you try to achieve finally with your code it could be helpful :slight_smile:


#4

Wow! Thanks for the link drop! I will definitely look into this.