Search code examples
pythonmaya

How do you get the Maya 'list; command to list the render layers in the order they are displayed in the render layer editor?


In Maya, when I list for the render layers in a scene, Maya returns the layers, but not always in the order they are displayed in its' legacy render layer editor. This is true after your change the name of an existing render layer, or add and subtract render layers. Is there a way to list for the layers and have Maya honor the order used in the render layer editor?

import maya.cmds as cmds cmds.ls(type = "renderLayer")


Solution

  • Render layers and display layers have an attribute called "displayOrder" which counts from the bottom -- so #1 is the lowest layer in the UI, #2 is the one above it, and so on. The default layer always has id 0.

    This will get you a dictionary of renderLayers where the keys are the orderings and the values are the layers:

    render_layers = {
        cmds.getAttr( i + ".displayOrder") : i for i in cmds.ls(type='renderLayer')
    }
    

    you can turn that into a list in display order:

    layers_in_order = [render_layers[x] for x in sorted(render_layers.keys())]