Maya Python API broken
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Maya's python api for setting the active Render Setup Layer is broken. Attached is a test file for Maya 2020.
File Contents
- Contains 2 render setup layers
- Render elements are added to default render layer, with overrides enabling/disabling them per render setup layer
The Issue
When i execute my python script, which is simply designed to just change the active Render Setup Layer, it does not update/change the state of the Render Elements, which in return renders incorrectly. You don't even have to render to see the issue. Just open the Render Dialog Setup and look at the Render Elements Panel. You'll notice they do not toggle.
Testing
1. Open the file and run the following code. You'll notice the render elements do not update to show their correct state of being disabled or enabled.
import maya.cmds as cmds
import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup
# Toggle between these to switch the active render setup layer
renderLayerName = 'bty'
renderLayerName = 'bkg' # comment out to switch between layers
# Broken Render Setup API
rs = renderSetup.instance()
layer = None
for x in rs.getRenderLayers():
if x.name() == renderLayerName:
layer = x
break
layer.makeVisible()
layer.setRenderable(True)
rs.switchToLayer(layer)
2. Working solution - run the code below toggling the renderLayerName variable to switch between the render layers and you'll now see it properly render and visibly update in the render dialog.
import maya.cmds as cmds
import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup
# Toggle between these to switch the active render setup layer
renderLayerName = 'bty'
renderLayerName = 'bkg' # comment out to switch between layers
# Working Solution
rsname = 'rs_{}'.format(renderLayerName)
cmds.editRenderLayerGlobals( currentRenderLayer=rsname)The difference in the render elements should look like this after executing the code...