Skip to content

Instantly share code, notes, and snippets.

@petfactory
Last active December 15, 2015 16:18
Show Gist options
  • Save petfactory/5287669 to your computer and use it in GitHub Desktop.
Save petfactory/5287669 to your computer and use it in GitHub Desktop.
Loops through all materials and if it has a VRay material ID it prints the material name, the ID and if selectMaterial is set to True it selects the materials.
import pymel.core as pm
import pymel.core.general
# select materials
allMat = pm.ls(materials=True)
vrayID = {}
selectMaterial = True
for mat in allMat:
# get the sg
sg = mat.listConnections(type='shadingEngine')[0]
# check if the vray material ID attr exists
try:
pymel.core.general.PyNode(sg+'.vrayMaterialId')
vrayID.update({sg: sg.vrayMaterialId.get()})
except AttributeError, error:
pass
#print(error)
for sg in vrayID:
# get the connected material
mat = pm.listConnections(sg, d=False, s=True)
id = vrayID.get(sg)
print(mat[0] + 'ID: %s' %id)
if(selectMaterial):
pm.select(mat, add=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment