The Render Setup Python API is available as part of the Maya installation, and you can find the relevant files in this folder: ..\Python\Lib\site-packages\maya\app\renderSetup.
To use the Render Setup API, you should first import the Render Setup module as follows:
import maya.app.renderSetup.model.override as override import maya.app.renderSetup.model.selector as selector import maya.app.renderSetup.model.collection as collection import maya.app.renderSetup.model.renderLayer as renderLayer import maya.app.renderSetup.model.renderSetup as renderSetup
You should also import maya.cmds so that you can use the native Maya commands.
The following is an example script that creates a layer and two collections. It then adds the sphere to the first collection using the expression mySphere*, and then adds the cube to the second collection with the expression myCube*.
import maya.app.renderSetup.model.override as override import maya.app.renderSetup.model.selector as selector import maya.app.renderSetup.model.collection as collection import maya.app.renderSetup.model.renderLayer as renderLayer import maya.app.renderSetup.model.renderSetup as renderSetup import maya.cmds as cmds rs = renderSetup.instance() # Create and append the render layer rl = rs.createRenderLayer("MyRenderSetupLayer") # Create and append 2 collections c1 = rl.createCollection("sphereCollection") c2 = rl.createCollection("cubeCollection") # Create a trivial scene with a cube, a sphere and a cylinder cmds.polySphere(name='mySphere') cmds.move(2, 'mySphere', y=True) cmds.polyCube(name='myCube') cmds.move(5, 'myCube', y=True) cmds.polyCylinder(name='myCylinder') cmds.move(10, 'myCylinder', y=True) # Set up collection 1 to select all spheres using the pattern mySphere*, # and collection 2 to select all cubes using the pattern myCube*. c1.getSelector().setPattern('mySphere*') c2.getSelector().setPattern('myCube*') # Set the render layer as visible. # Only the sphere and the cube are displayed as they are collection members. rs.switchToLayer(rl)
Render Setup commands are available that allow you to query render setup membership.
To find out more about these commands:
renderLayerMembers
renderSetupFindCollections
renderSetup
renderSetupLegacyLayer
Query the docs strings using help().
For example, the following Python commands allow you to query the renderLayerMembers command:
import maya.app.renderSetup.model.modelCmds as modelCmds help(modelCmds.RenderLayerMembersCmd)
You can query the docs strings for the other commands in a similar fashion.
To find out more about the renderSetupSelect command, enter these commands in the Python tab of the Script Editor:
import maya.app.renderSetup.views.viewCmds as viewCmds help(viewCmds.RenderSetupSelectCmd)
You can define functions as follows that imports and exports a Render Setup .json file into the scene.
import maya.app.renderSetup.model.renderSetup as renderSetup import json # Cannot name function "import", as this is a reserved Python keyword. def importFile(filename): with open(filename, "r") as file: renderSetup.instance().decode(json.load(file), renderSetup.DECODE_AND_OVERWRITE, None) def exportFile(filename): with open(filename, "w+") as file: json.dump(renderSetup.instance().encode(None), fp=file, indent=2, sort_keys=True)