Tracking switching between View Layers

The Blender Python API does not provide a special handlers for tracking View Layers switching. However, if it needs to perform some action when switching them, we can track their switching using the message bus.

First, let’s define a function that will be executed when switching View Layers. For example, it can set different positions of the Render Region for different view layers.

Open the Text Editor in Blender and define the function:

The first command of the function turns on the Region Border mode.

Next, for the first View Layer with the “ViewLayer” name, the region border will be set in the lower left part of the screen – from the lower left corner to the center.

And for the second View Layer (and for all the others), the region border will be set in the upper right part of the screen – from its center to the upper right corner.

Now let’s subscribe our function as an event handler when the View Layers switches using the message bus “msgbus”.

The first “key” parameter is passed a pointer to the object being tracked, in our case it is the window type “bpy.types.Window” and the “view_layer” property, the change of which needs to be tracked.

The second “owner” parameter is the owner of the event. In common case, the “bpy” is most often used.

The third “args” parameter is used to pass additional values ​​to the handler function. In our case, passing something to our function is not required.

And the last “notify” parameter is a pointer to a function that will be executed when the property specified in the first parameter changes. Here we set our “on_view_layer_change” function for resizing the region border.

Execute the script by pressing the Run Script button in the Text Editor window.

Now, when switching View Layers, the location of the render region border changes.

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments