Community
Maya Programming
Welcome to Autodeskโ€™s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results forย 
Showย ย onlyย  | Search instead forย 
Did you mean:ย 

How to Delete a Render Setup Layer Using Python?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
3933 Views, 5 Replies

How to Delete a Render Setup Layer Using Python?

Anonymous
Not applicable

Hello!

 

Anyone know how to delete a render layer in the new render setup using python? Right clicking on a layer and hitting delete works, but I have no idea what command it's firing to delete the layer and any associated collections/overrides. Deleting the layer node directly causes all the errors ๐Ÿ˜•

 

Thanks for your time and help!

0 Likes

How to Delete a Render Setup Layer Using Python?

Hello!

 

Anyone know how to delete a render layer in the new render setup using python? Right clicking on a layer and hitting delete works, but I have no idea what command it's firing to delete the layer and any associated collections/overrides. Deleting the layer node directly causes all the errors ๐Ÿ˜•

 

Thanks for your time and help!

5 REPLIES 5
Message 2 of 6
g2m.agent
in reply to: Anonymous

g2m.agent
Collaborator
Collaborator

I just know how to remove all render layers:

 

import maya.app.renderSetup.model.renderSetup as renderSetup

rs = renderSetup.instance()

rs.clearAll()

I just know how to remove all render layers:

 

import maya.app.renderSetup.model.renderSetup as renderSetup

rs = renderSetup.instance()

rs.clearAll()
Message 3 of 6
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Same question, I can't delete an "specific" render layer (not all)  with python with render setup. 

0 Likes

Same question, I can't delete an "specific" render layer (not all)  with python with render setup. 

Message 4 of 6
danielhhhh
in reply to: Anonymous

danielhhhh
Explorer
Explorer

Wish there was a direct Python call to delete individual layers but this worked for me:

 

# get the renderSetup JSON data
data = renderSetup.instance().encode(None)

# get render layers
old_layers = data['renderSetup']['renderLayers']
 
# filter however you want to
new_layers = [x for x in old_layers if x['renderSetupLayer']['name'] != 'YOUR_LAYER_NAME']

# replace the render layers
data['renderSetup']['renderLayers'] = new_layers

# write the new render setup data
renderSetup.instance().decode(data, renderSetup.DECODE_AND_OVERWRITE, None) 

 

Also works with collections: 

 

for layer in data['renderSetup']['renderLayers']:
    if layer['renderSetupLayer']['name'] == 'YOUR_LAYER_NAME':
        old_collections = layer['renderSetupLayer']['collections']
        new_collections = [x for x in old_collections if x['collection']['name'] != 'YOUR_COLLECTION_NAME']
        layer['renderSetupLayer']['collections'] = new_collections

 

0 Likes

Wish there was a direct Python call to delete individual layers but this worked for me:

 

# get the renderSetup JSON data
data = renderSetup.instance().encode(None)

# get render layers
old_layers = data['renderSetup']['renderLayers']
 
# filter however you want to
new_layers = [x for x in old_layers if x['renderSetupLayer']['name'] != 'YOUR_LAYER_NAME']

# replace the render layers
data['renderSetup']['renderLayers'] = new_layers

# write the new render setup data
renderSetup.instance().decode(data, renderSetup.DECODE_AND_OVERWRITE, None) 

 

Also works with collections: 

 

for layer in data['renderSetup']['renderLayers']:
    if layer['renderSetupLayer']['name'] == 'YOUR_LAYER_NAME':
        old_collections = layer['renderSetupLayer']['collections']
        new_collections = [x for x in old_collections if x['collection']['name'] != 'YOUR_COLLECTION_NAME']
        layer['renderSetupLayer']['collections'] = new_collections

 

Message 5 of 6
danielhhhh
in reply to: danielhhhh

danielhhhh
Explorer
Explorer
Accepted solution

Scratch my previous reply, found a way with just a couple direct calls:

 

import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup

rs = renderSetup.instance()
layer = rs.getRenderLayer('YOUR_LAYER_NAME')
renderLayer.delete(layer)

 

Scratch my previous reply, found a way with just a couple direct calls:

 

import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup

rs = renderSetup.instance()
layer = rs.getRenderLayer('YOUR_LAYER_NAME')
renderLayer.delete(layer)

 

Message 6 of 6
Anonymous
in reply to: danielhhhh

Anonymous
Not applicable

just in case someone wants to delete collections:

 

 

import maya.app.renderSetup.model.renderSetup as renderSetup 
import maya.app.renderSetup.model.collection as collTool

layer = 'your_layer'
collName = 'your_collection' (can be just a part of the name)

render_setup = renderSetup.instance()
render_layer = render_setup.getRenderLayer(layer) 

collections = render_layer.getCollections()
if collections:
    for coll  in collections:
        if collName in coll.name():
            collTool.delete(coll) 
            print 'deleted ', collName,'from',layer

 



0 Likes

just in case someone wants to delete collections:

 

 

import maya.app.renderSetup.model.renderSetup as renderSetup 
import maya.app.renderSetup.model.collection as collTool

layer = 'your_layer'
collName = 'your_collection' (can be just a part of the name)

render_setup = renderSetup.instance()
render_layer = render_setup.getRenderLayer(layer) 

collections = render_layer.getCollections()
if collections:
    for coll  in collections:
        if collName in coll.name():
            collTool.delete(coll) 
            print 'deleted ', collName,'from',layer

 



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report