Page MenuHome

API/BPY: visible_get() throws an exception if the object is Excluded from View Layer
Closed, ResolvedPublic


System Information
Operating system: Windows-10-10.0.17763 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.86

Blender Version
Broken: version: 2.80 (sub 74), branch: master, commit date: 2019-07-11 13:50, hash: rB06312c6d2db8

Short description of error
visible_get() throws an exception when an object is excluded (via the Collection it belongs to)

Exact steps for others to reproduce the error
Move an object (Cube) to a new collection
Exclude that collection from the View Layer (in the outliner)
In the Python console, run:

# or

It will throw an Exception saying:

RuntimeError: Error: Object 'Cube' not in View Layer 'View Layer'!

The description of visible_get() says "Test if the object is visible in the 3D viewport, taking into account all visibility settings", which it currently doesn't.

Without being able to use visible_get(), you have to catch the exception of either visible_get() or other functions that throw the same exception in the same situation, so your add-on works smoothly.

Event Timeline

Philipp Oeser (lichtwerk) closed this task as Archived.
Philipp Oeser (lichtwerk) claimed this task.

Thx for the report, but I think this is supposed to work that way.
This gets visibility per view layer.
This has to be specified, because e.g. you can have different windows in blender showing different view layers (thus different viewports with different visibilities set).
[not specifying one will take the active, same as C.view_layer]

So there is not just the "one 3D viewport" (maybe the doc wording could be improved here) to get visibility from, it is dependent on the view layer.
I even think it is good that it throws the error [one could argue to just return False if the object is not in the view layer], makes you think "in view layers" more...

Not sure what the exact usecase is here? Exporter? Something else?
If you are iterating over objects, why not iterate over view_layer.objects?
If you need to use an object which you are not sure of that it is in a particular view_layer, you need to check first to not run into the error.
(something like D.objects['Cube'] in [o for o in C.view_layer.objects])

That being said, this is not a bug, will archive the report...
(@Christopher Hindefjord (chrish): feel free though to comment again if issues always welcome here)

@Brecht Van Lommel (brecht): hope I havent represented something wrong here... I was actually thinking about this quite some more yesterday evening and was leaning more and more into the direction of returning False... so: nice :)