It seems that the property scene.render.layers['RenderLayer'] is no longer available in blender-2.8. I just want to set the use_pass_uv property of the current scene, then what should I do?

'scene.render.layers['RenderLayer'].use_pass_uv=True' works well in blender-2.7, but in blender-2.8, there was an error like this ''AttributeError: 'RenderSettings' object has no attribute 'layers

  • $\begingroup$ 'scene.render.layers['RenderLayer'].use_pass_uv=True' works well in blender-2.7, but in blender-2.8, there was an error like this ''AttributeError: 'RenderSettings' object has no attribute 'layers' $\endgroup$ – Affection Jul 3 at 2:11
  • 1
    $\begingroup$ You can use the edit link at the bottom of your post to modify the text instead of using comments. $\endgroup$ – susu Jul 3 at 3:14

Render layers have been replaced by View Layers. Recommend do a search in the API docs or use the python console to figure out how to access the ViewLayers of the current scene:

 >>> C.scene.view_

>>> for vl in C.scene.view_layers: # Iterate through all view layers
...     print (vl.name) # print the name
View Layer
View Layer.001
View Layer.002

You can also access the current ViewLayer (in context) by using bpy.context.view_layer (or by using C convenience variable in the console C.view_layer):

>>> C.view_layer # View layer reference
bpy.data.scenes['Scene'].view_layers["View Layer"]

>>> C.view_layer.name # View layer name
'View Layer.001'

Another way is using get(<LAYERNAME>) on Scene.ViewLayers collection:

>>> C.scene.view_layers.get('View Layer')
bpy.data.scenes['Scene'].view_layers["View Layer"]

>>> my_vl = C.scene.view_layers.get('View Layer')
>>> my_vl.name
'View Layer'

Basic example on how to set attributes of the current view layer (in context):

import bpy

# Get the current view layer
vl = bpy.context.view_layer

# Set uv pass attribute
vl.use_pass_uv = True

# Set normal pass attribute
vl.use_pass_normal = True

# Enable diffuse light passes
vl.use_pass_diffuse_direct = True
vl.use_pass_diffuse_indirect = True
vl.use_pass_diffuse_color = True

Example on how to enable the 'UV' as well as the 'Normal' pass on all view layers in the scene:

import bpy

for vl in bpy.context.scene.view_layers:
    vl.use_pass_uv = True       # Enable UV pass
    vl.use_pass_normal = True   # Enable normal pass
| improve this answer | |
  • $\begingroup$ Thanks for your kindly reply! It helps solving my problem. $\endgroup$ – Affection Jul 8 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.