Backup Script
home
Setup

Creating Programs

Programs are a set of instructions that you give blender. These instructions are represented by different nodes. The order you place the node in is the order these instructions will run in.
An example could be Adding an object → Moving the object to a collection → Renaming the collection. Each of these instructions would be represented by one or more nodes which get placed in this order.
Programs are represented with execute sockets that have a white diamond shape. They are program sockets, meaning they follow a path from left to right, starting at a trigger node like an operator or an event.
In blender a set of operations that you want to run at some point are started by an operator. An operator is for example what runs when you click on a button. This is just the starting point for the list of instructions.
There are different starting points like specific events, for example when a file gets loaded, when a render finishes or when the user presses a specific keyboard shortcut.
Operators can be created with the Operator node. You can then select these in a button node. The operation will then start from the Execute output of the operator node, continuing down the chain following the execute sockets.
Above is an example of a simple condition that runs different parts of the program. First, we follow the program starting at the Operator. This could be selected in a button and run from there.
We get to the If/Else node which has three different Execute outputs. The node also has a boolean (True or False, also represented by a checkbox) input which takes a simple comparison statement. Here the input gets evaluated: 100 > 1 . As this condition is true, the True output runs next.
This runs the print node which prints one to the system console. We could now attach more nodes to the output of the print node to run them in that row. This makes execute sockets different from interface sockets as those end at certain nodes.
The False output doesn’t get run because the condition was True. Next, we run the Continue socket. This continues the program after the If statement is completed, meaning either the True or False outputs have run. Here we print after if. Again we could now attach more nodes to run other operations after the print.
Another useful operation is the For Loop. Here we can run something for every item in a list or collection. A collection is blenders way of storing multiple data elements, for example, all objects in the scene.
The nodes above run the print node for every object in the scene. We plug in the All Objects output to run the loop for every object in the file. The Item output then represents the current object at any point in the loop. We can now take this and attach it to our print node which is connected to the Repeat output to run on every step of the loop.
As with the interface nodes, we can also use functions here to reuse parts of the nodes. This avoids duplicating nodes for doing the same thing.

Operators vs Property Functions

The Run Operator node allows you to run any operation you can find in blender. With this, it’s tempting to just use this to create your programs. While this is possible, it should be avoided if possible.
There are multiple reasons for this. One is that operators require a context. You may notice that certain operators don’t work. In the console, you’ll see a poll error. This is most likely because the operator needs to be run in a certain area, for example, the 3D view. Some might even need specific details like an active object. There’s no way to find this context, apart from going to the blender source code and checking for a specific operator.
Another reason is that operators don’t return values. This means that when you do something like creating a material, you won’t have direct access to that material. You will need to find it afterward, for example by its name. This can lead to all kinds of issues. When a material with the same name already existed it might now be named Material.001 and you can’t find it.
For these reasons, you should try to avoid using operators. Sometimes there is no other way though.
The alternative to blender operators is to use property functions that run on blender data. This is explained in more detail in blend data, but generally, you find them on the data you’re referring to (Create Material is on Materials) in the blend data browser and run them with the Run Property Function node.
TOP