Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active December 3, 2020 18:26
Show Gist options
  • Save patwooky/95b117e672e77a957e08c68022c8cfc4 to your computer and use it in GitHub Desktop.
Save patwooky/95b117e672e77a957e08c68022c8cfc4 to your computer and use it in GitHub Desktop.
this script reverses the order of render layers in the new Render Setup Window in Maya 2016 and above
# 20190204_maya2017_renderLayersReorder_v002
# Written by Patrick Woo ([email protected])
# this script reverses the order of render layers in the new Render Setup Window in Maya 2016 and above
# the scene must have at least 2 render layers to see the re-order effect
# changes:
# - the first item in the list can now be re-ordered just like the rest of the layers, by first detaching then re-attaching
# - this version allows re-ordering every render layer by first detaching them (previously there was no detaching)
# - if you have the Render Setup Window open, the layer order now reflects and refreshes without having to re-open the window
def render_layers_reorder():
# code for querying render layers is taken from
# https://fredrikaverpil.github.io/2017/05/07/querying-render-setup-in-maya-2017/
# [email protected]
import maya.app.renderSetup.model.renderSetup as renderSetup
render_setup = renderSetup.instance()
render_layers = render_setup.getRenderLayers()
print ('initial order of render layers')
print ('{} render layers, {}'.format(len(render_layers), [x.name() for x in render_layers]))
reverse_list = render_layers
reverse_list.reverse()
# detach all child layers
[render_setup.detachChild(x) for x in render_layers]
# re-attach the re-ordered child layers (the first layer has the position of 1, not 0)
[render_setup.attachChild(idx, x) for idx, x in enumerate(reverse_list, 1)]
print ('final order of the render layers')
print ('{} render layers, {}'.format(len(render_layers), [x.name() for x in render_setup.getRenderLayers()]))
render_layers_reorder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment