Page MenuHome

RNA: Expose bases in ViewLayer to python
AbandonedPublic

Authored by Erik Abrahamsson (erik85) on Nov 16 2020, 2:28 AM.

Details

Reviewers
None
Group Reviewers
Python API
Summary

This patch exposes the bases of a view layer to Python.
Code example to hide all objects with a name starting with 'C' from the viewport, in the current view_layer:

import bpy

for base in bpy.context.view_layer.bases:
    if base.object_name[:1] == 'C':
        base.hide_viewport = True

Bases can also be accessed with object name like this: bpy.context.view_layer.bases['Camera'].

Diff Detail

Repository
rB Blender

Event Timeline

Erik Abrahamsson (erik85) requested review of this revision.Nov 16 2020, 2:28 AM
Erik Abrahamsson (erik85) created this revision.
Erik Abrahamsson (erik85) edited the summary of this revision. (Show Details)

I would rather this doesn't get accepted. The reasoning behind not exposing bases in the API was deliberate in the 2.8 project. They add complexity to the API and it is not something users are familiar with.

We can still think of ways for the API to support this feature request case (e.g., passing v3d as argument to visible_get). But please not by exposing bases.

I thought we had a way already though to do something similar.

I trust that you know by your huge experience what you are talking about, but from my point of view it's definitely the easiest way to access view layer specific settings per object and really should be possible through the API.
The two properties available are hide_viewport and select. Who knows, maybe in the future there will be more view layer specific settings and then those will appear automagically instead of making workarounds for those too.

Closing this because I discovered it's already possible through Object.hide_set(state, view_layer)