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)