0

I am trying to get hold of the objects included in a collection in Mayas new renderlayer system. I can get the ones in the include field, but not the ones added through add or drag and drop.

Basically what I am trying to do is finding all the lights that are active in the scene but as the new lighteditor is to unstabile we have decided to use collections instead so I will need to figure out which lights in the scene is within a collection or a child of a group that's in a collection and whether that group has been disabled. This is my super simple script so far that only works as long as the lights are added as a "pattern" next to the include text field.

#modules
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 mc

rs = renderSetup.instance()

rl_test = rs.createRenderLayer("Layer") # create renderlayer
cl_test_lights = rl_test.createCollection("Prod_lights")
cl_test_lights.getSelector().setPattern('Prod_lights_grp')
cl_test_lights.setSelfEnabled(0) #disable collection
collections = rl_test.getCollections() #get collections within renderlayer

DeactivatedLightsLi=[]
for each in collections: 
    if each.isSelfEnabled()==False: #if collection is disabled
    pattern = each.getSelector().getPattern() 
    DeactivatedLightsLi.append(pattern) #add this pattern to the list

Maya screengrab, to visualise what I am after

1 Answers1

0

Well seems like I eventually found my answer so maybe it can help someone else. Was actually an answer on another post that put me on the right track. His answer didn't work for me, but gave me a keyword to search for to find the information I needed in the rendersetup documentation.

C:\Program Files\Autodesk\Maya2018\Python\Lib\site-packages\maya\app\renderSetup\model\selector.py

#modules
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 mc

rs = renderSetup.instance()

rl_test = rs.createRenderLayer("Layer") # create renderlayer
cl_test_lights = rl_test.createCollection("Prod_lights")
cl_test_lights.getSelector().setPattern('Prod_lights_grp')
cl_test_lights.setSelfEnabled(0) #disable collection
collections = rl_test.getCollections() #get collections within renderlayer

DeactivatedLightsLi=[]

for each in collections: 
    if each.isSelfEnabled()==False: #if collection is disabled
        pattern = each.getSelector().getPattern() 
        DeactivatedLightsLi.append(pattern) #add this pattern to the list
        dragged = each.getSelector().getStaticSelection()
        DeactivatedLightsLi.append(dragged) #add this elements also to the list

print(DeactivatedLightsLi)