Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Last active April 14, 2016 08:59
Show Gist options
  • Save tokejepsen/f5315c0e7f9de22a5b319374d9700774 to your computer and use it in GitHub Desktop.
Save tokejepsen/f5315c0e7f9de22a5b319374d9700774 to your computer and use it in GitHub Desktop.
Maya: Set Attribute On Renderlayer
import pymel.core
drg = pymel.core.PyNode('defaultRenderGlobals')
# dict of attributes and values to set.
# needs to include node name as well.
# Note that time values are divided by the framerate, ei. 10 frame / 25 frame/sec = 0.4 sec
attrs = {'defaultRenderGlobals.startFrame': 0.4}
# iterate over the selected renderlayers.
# can select renderlayers through the outliner with "Display" > "DAG Objects Only"
for layer in pymel.core.ls(selection=True, type='renderLayer'):
# setup the layer override
for attr in attrs:
pymel.core.editRenderLayerAdjustment(attr, layer=layer.name())
# finding the layer override through the connections
# and setting the attribute values
if layer.adjustments.get(multiIndices=True):
for count in layer.adjustments.get(multiIndices=True):
if not layer.adjustments[count].plug.connections():
continue
if layer.adjustments[count].plug.connections()[0] == drg:
layer_attr = layer.adjustments[count].plug.connections(plugs=True)[0]
for attr in attrs:
if layer_attr == attr:
layer.adjustments[count].value.set(attrs[attr])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment