Reference/Release Notes/2.80/Python API/Scene and Object API

= Blender 2.80: Scene and Object API =

View Layer & Collection
2.8x collections replace both groups and the fixed twenty scene's layers of 2.7x. That means that objects belonging to a collection can both be instantiated (from another Empty object, on particles, etc.), and organized as regular objects in a scene, when their collection is linked into the scene's hierarchy of collections.

Each scene has a master collection, which is part of the scene data, and not in the Main database (i.e. you won't find it in, pretty much like root node trees of materials etc.). It is the root of the collections tree of that scene.

While in 2.7x layer belonging was defined in the object, in 2.8x the object must be linked to the desired collections. And while in 2.7x you always had twenty layers, in 2.8x you have to ensure you have desired collections yourself.

2.7x:

2.8x:

2.8x view layers replace and extend 2.7x render layers. The main difference is that they also control what is visible in the scene, not only for rendering, and the whole organization of collections.

View layers replicate the collection hierarchy of their scene, but they give access to a light wrapper around those, LayerCollection, which among other things allow to exclude a given collection from a given view layer. By default, all collections linked to a scene will be part, active in all its view layers.

2.7x:

2.8x:

Note that in 2.8x, you get the active view layer from the active window, not the active scene.

Scene update
2.7x:

2.8x:

Object Selection and Hiding
In 2.7x, you could directly (de)select an Object from its select property. This has been removed in 2.8x, in favor of some get/set functions.

2.7x:

2.8x:

See the API documentation for details.

Hiding works nearly the same in 2.8x than in 2.7x, the only difference is that, for consistency, the hide property has been renamed to hide_viewport.

2.7x:

2.8x:

However, collection hide status also matters in 2.8x. An object only linked in hidden collections will always be hidden, regardless of its own flag setting. This is similar to hiding a layer in 2.7x.

Adding Objects
In 2.7x objects were added to (and owned by) a Scene. In 2.8x, they are added to (and owned by) a Collection. See above for details about collections and view layers.

2.7x:

2.8x:

A same object can be in as many collections as you want - but it will still be a single object (a single instance). An object will be hidden from a scene only if it is hidden itself, or if all the collections it belongs to are hidden, or excluded from active view layer.

Note that  still exists in 2.8x, but as a mere read-only flat list of all objects instantiated in the scene, you cannot directly edit it anymore in any way.

Instancing
Access to dupli instances has completely changed. In 2.7x, you could access all instances generated from one object like this:

2.7x:

In 2.8x, instances are only available inside of the depsgraph context. So you do not need to create them anymore, just loop over them. But you need a depsgraph to do this.

2.8x:

WARNING: Do not store any reference to this dupli, nor any of its IDs. That data is generated on the fly, and becomes invalid as soon as you iterate to the next item or leave the iterator context. Furthermore, ID RNA pointers will point to evaluated ones. You must duplicate any data (like dupli matrix etc.) if you want to store it.

Another big difference is that you do not have duplis per objects anymore, only the whole lot of instances in the current depsgraph. This includes 'real' object ones:

2.8x:

You can get the duplis of a specific object with this kind of iterator:

A depsgraph can currently be retrieved from a Context or ViewLayer, but there is no way to get a 'render' depsgraph for now. The API will have more advanced handling of depsgraphes in the future, but at this time it is still WIP.

Multi-Object Modes
Multiple objects can now be in edit and pose mode at the same time, whereas previously there was only one object. Operators need to be updated to affect all objects in the active mode.

To test which mode is active, use context.mode. Accessing objects in this mode can be done with two new context attributes:


 * context.objects_in_mode: list of all objects in the mode.
 * context.objects_in_mode_unique_data: when multiple objects share the same data, list only one object per unique object data. This is the most commonly used attribute, as usually each mesh or other object data should be edited once.

Base and context override
We no longer expose ObjectBase in the Python API, so we removed `scene.object_bases`. That means when overriding the context for certain operator calls there is no need to set:
 * `visible_bases`
 * `selectable_bases`
 * `editable_bases`
 * `selected_editable_bases`
 * `active_base`