Python

Making a cancellable operator in Blender uncancellable

When defining custom operators in Blender, we can make them cancellable and uncancellable by specifying the “UNDO” value in the “bl_options” parameter of the operator. But what if we need to exclude an existing operator, for example, a system operator, from the undo queue? This is very easy to do by redefining the operator with our own, without specifying “UNDO” in its parameters.

Operators with undo (Ctrl + z) and without

Defining operators, we most often provide for the ability to undo the action they performed – if after executing the operator the user presses the Ctrl + z key combination, all the effects of the operator on the scene should be canceled. However, in some cases, it may be necessary to define an operator that will be ignored if the user tries to undo its actions. Blender’s API allows us to create both types of operators by simply specifying the ability or prohibition of undo in their parameters.

Custom Icons for EnumProperty in Blender

We can use custom icons, icons loaded from external files, and not embedded in Blender libraries, for example, to add customization to operator call buttons in UI panels. However, it is not only buttons that may require custom icons. Using the Blender Python API, we can add customization to drop-down list items or switches that are created based on the EnumProperty type.

Placing Max/Min socket controls of geometry node on the user panel

In order to display the value of a socket on the Geometry Nodes modifier panel in Blender, we simply need to create a link and connect the desired socket of the desired node with an empty socket on the Group Input node. After this, a field appears in the modifier panel in which we can change the value of the desired socket. We can then place this field on the user panel by accessing it as a dynamic property.

Changing the order of sockets in Blender Geometry Nodes groups

We can change the order of sockets in a Blender Geometry Nodes node group manually by simply dragging it – in the N-panel in the Group – Interface tab, hold down the desired socket and drag it with the mouse to the desired place. We can move a socket in a group node to a new location using the Blender Python API with the move() function of the “interface” object.

Labels for Reroute nodes in Blender Geometry Nodes

Did you know that you can set your own text labels for Reroute nodes in Blender Geometry Nodes? Since Reroute nodes are most often used to simplify and improve the readability of node trees in Geometry Nodes, marking such nodes with a label with a short informational inscription can be very convenient – you will not need to remember or scroll through the tree of nodes every time to find out where this Reroute data comes from.

Quickly setting the point at which the light sources in the scene should be directed

When we set up lighting in a scene in Blender, we usually set the direction of the light to the desired point manually for each light source. However, this process can be simplified and we can specify the point to which all selected light sources in the scene will be directed at once.

Moving the Auto Smooth modifier to the end of the modifier list

Since version 4.1, the normal smoothing operator in Blender has been completely replaced by a modifier implemented on the Geometry Nodes mechanism. This is convenient for solving a number of problems, but if the Auto Smooth modifier is not located on the last place in the modifier stack, before other modifiers that change the mesh geometry, this leads to the appearance of artifacts. To quickly move the Auto Smooth modifier to the end of the stack, we can use a simple script.

Working with Mean Bevel Weight using the Blender Python API

To interact with the Bevel modifier, which creates a bevel on specified edges, each of the required edges must be given a specific numeric weight parameter ranging from 0.0 to 1.0. In manual mode, the weight for the bevel is set in the N-panel on the Item tab in Edges Data – Mean Bevel Weight field. This weight can also be read and set via the Blender Python API.