Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
Last active July 12, 2019 08:45
Show Gist options
  • Save fredrikaverpil/af406951fb8feb013c03dd1a7a816d7d to your computer and use it in GitHub Desktop.
Save fredrikaverpil/af406951fb8feb013c03dd1a7a816d7d to your computer and use it in GitHub Desktop.
Export/import shader assignment with Maya
import maya.cmds as cmds
import json
# Create the dictionary "data" with shadergroup as key
data = {}
shaders = cmds.ls(type='shadingEngine')
for shader in shaders:
data[shader] = []
# Append all shapes to each shadergroup-key
for transform in cmds.ls(type='transform'):
shapes = cmds.listRelatives(transform, fullPath=True)
shaders = cmds.listConnections(shapes, type='shadingEngine')
if not isinstance(shaders, type(None)):
for shader in shaders:
for shape in shapes:
data[shader].append(shape)
with open('shader_assignment.json', 'w') as outfile:
json.dump(data, outfile, sort_keys=True, indent=4, ensure_ascii=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment