When starting Blender from the console it processes all parameters passed through the command line. However, some scripts and add-ons for proper work may require specifying their unique command line arguments. If you specify such additional parameters in the command line, Blender will also try to process them, which is likely to result in an error. Blender provides a special way to exclude such arguments from own processing.
State switches so-called “radio buttons” are used in the case to limit the choice by one value from several available ones. There are a lot of such buttons in the Blender interface, for example, switching between RGB and BW rendering modes or setting the texture mapping mode. Such buttons can be created in the Blender add-ons interface too.
Single add-on or script can contain several different operators, and not all of them may be registered in the API by the register() function. To verify that the required operator is registered in the Blender API, run the following command:
It is convenient to use the following system for debugging developing multi-file Blender add-ons. But it has one drawback: modules imported in __init__.py file becomes available only after the file running (after the execution of the register() function). This means that any access to the imported modules before they are registered will cause an error. This is not critical in most cases, but it will cause a problem if, for example, in one imported module is used inheritance from the class, described in the other imported module, because the classes descriptions are processed before the add-on registration.
To get more freedom working with imported modules, we can use another way to debug the add-on – do not run the add-on directly from the development directory, but install it in Blender and check its “live” work. However, manual add-on reinstallation requires a set of routine actions, which complicates such sort of debugging. This issue can be solved by reinstalling the add-on in automatic mode.
In addition to common panels (N/T/Properties) and their sub-panels, to display the user interface elements while developing Blender add-ons you can also use pop-up panels appearing on the screen when a user presses a certain key combination or perform any action. The simplest example of such panels is the panel that appears when the f6 key is pressed immediately after adding an object (shift+a) to the scene.
Blender API provides developers the ability to create such panels for their add-ons. Let’s consider the creating of a pop-up panel as an example of the “Message box” window.
Storing data in a remote database has become common practice in the development of software products. Blender is no exception. Writing scripts and add-ons, the developer may need to access the database to retrieve from it or write to it the necessary information. MySQL today is one of the most common and widely available databases and is well suited for working with Blender.
The interaction between Blender and MySQL database through the Blender Python API is not difficult, but it needs some preparation before stating:
Sometimes when creating an animation it is necessary to perform some actions according to the timeline or, the same, to the current animation frame number. Binding animation to timeline frames in Blender is possible using the built-in Python API.
As an example, let’s make a simple animation which turns one of the letters of any text from lowercase to uppercase in series.
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.
Blender has the ability to limit the scope of rendering – outlining a region the special render border and checking the Border checkbox on the Render – Dimensions tab in Properties window. If such frame is set – Blender render only a limited area of the image.
There are two ways to set render border via the Blender API:
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.