Blender

Creating multifile add-on for Blender

In the development of complex add-ons with large code volume storing all the code in a single file is inappropriate. When a single file contains logically unrelated classes, functions, and datasets, it is difficult to read, debug, find the necessary code pieces, reuse code. Such code layout is considered as very bad programming tone.

Blender Python supports modular system that allows subdividing logical code parts of the add-on into different files, and then connect them to use. Even if you have never thought about modules, creating scripts or add-ons, you have already used them – any code stored in the *.py file is a separate independent module. Just your addon consists of only one module. Complex add-ons may consist of several tens of modules.

Multifile add-on
Multifile add-on

How to check errors if Blender closes together with system console window

Sometimes when debugging scripts or add-ons, errors not only interrupt the code execution but also causes the complete closure of Blender together with its system console. This case its impossible to check errors and view errors messages.

To find a failure, Blender can be started from the command line interpreter cmd. In this case, Blender output log is redirected to the cmd window which, when the program falls due to errors, not closed. If Blender closes all error messages stay available to check in the cmd window.

Running Blender from command line interpreter cmd
Running Blender from command line interpreter cmd

To start Blender from a command line interpreter:

  1. Start the interpreter ( “Start” – Run – cmd)
  2. In the cmd window type the full path to the installed Blender. For example: C:\”Program Files”\blender-2.78a-windows64\blender.exe

Part of the way contains spaces must be enclosed in double quotes – like “Programm Files” in this example.

Accurate Render Border add-on

Blender add-on allows setting accurate coordinates for render border.

After add-on installation in T-bar additional “ARB” tab appears. On this tab, it’s possible to set accurate values for left-top and right-bottom render border corners coordinates in pixels. Coordinates establish relative to the render size (Properties — Render — Dimensions — Resolution). After pressing the “Set Accurate Render Border” button render border determines in accordance with the entered values.

Add-on is free and open-source. If you want to support it – you can buy the add-on for a convenient price, or set the price to 0 to download it for free.

Creating Blender Add-ons variables with values saved in blend-files

All user-defined classes (panels, operators), registered in Blender API, exists only during Blender runs. After program close they are deleted from memory. Therefore, if some variables are defined in user classes, all of them will be reset after Blender restart.

However, sometimes it is necessary to use in Blender add-on variables with values that not be lost in the process of program restarting. To retain variables values, it needs to wrap them into special class – property, and attach to any object whose properties are stored in * .blend file.

Variables in Blender API operator classes

User defined operator classes, inherited from bpy.types.Operator, are static. Accordingly, only static variables can be defined in them.

Static variable sampleVar definition in SampleClass class: