@@ -0,0 +1,767 @@
+# -*- coding: utf-8 -*-%0Afrom contextlib import contextmanager%0A%0Aimport maya.app.renderSetup.model.renderSetup as renderSetup%0Afrom maya import cmds%0A%0A%0A@contextmanager%0Adef enabled_render_layers():%0A    old_layer = cmds.editRenderLayerGlobals(query=True, currentRenderLayer=True)%0A    try:%0A        rs = renderSetup.instance()%0A%0A        def switchToLayer(layer):%0A            def _switch():%0A                rs.switchToLayer(layer)%0A            return _switch%0A%0A        enabled_layers = %5B%5D%0A        for layer in rs.getRenderLayers():%0A%0A            layer.switchToLayer = switchToLayer(layer)%0A            if layer.isRenderable():%0A                enabled_layers.append(layer)%0A%0A        yield enabled_layers%0A    finally:%0A        cmds.editRenderLayerGlobals(currentRenderLayer=old_layer)%0A

Add enabled_render_layers context manager.