Last active
December 14, 2015 12:16
-
-
Save csaez/afc4e41ea630593f59b9 to your computer and use it in GitHub Desktop.
MAYA: quick and dirty way to save/load shading states between render layers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as mc | |
if not hasattr(mc, "CLIPBOARD"): | |
mc.CLIPBOARD = dict() | |
def get_shading(node): | |
rval = dict() | |
type_ = cmds.nodeType(node) | |
if type_ != "transform": | |
return rval | |
for shape in cmds.listRelatives(node, s=True, f=True) or []: | |
sg = cmds.listConnections(shape, t="shadingEngine") or [] | |
if len(sg): | |
rval[shape] = sg[0] | |
return rval | |
def save_shading_state(nodes=None): | |
mc.CLIPBOARD.clear() | |
nodes = nodes or cmds.ls(sl=True, l=True) | |
for node in nodes: | |
mc.CLIPBOARD.update(get_shading(node)) | |
def load_shading_state(): | |
for k, v in mc.CLIPBOARD.iteritems(): | |
cmds.sets(k, edit=True, forceElement=v) | |
save_shading_state() | |
load_shading_state() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment