Scripts

How to install and uninstall Blender add-on via python API

Blender add-ons installation and uninstallation can be managed through the python API. Use the following commands in a script:

To deactivate the add-on:

To uninstall the add-on:

Mesh Custom Properties editing through the Blender API

New mesh Custom Property can be created through the Blender python API by executing the following code:

with:

  • object_name – name of the mesh
  • property_name – new custom property name
  • property_value – value of this new property

After executing this command, the new property will be created and will be available in the Properties window – Object panel – Custom Properties sub-panel.

Like any object custom properties, the created property has a number of parameters that can be accessed by clicking the Edit button. These parameters can also be changed through the API.

Creating pop-up panels with user UI in Blender add-on

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.

Active objects access

How to access the active (selected) objects through the Blender Python API from scripts/add-ons:

  1. The active window (in which current action occurs):

  1. The active scene:

  1. The active (selected) mesh:

  1. The active (selected) material node (in the NODE_EDITOR window):

  1. The active (selected) material node (in the COMPOSITING window):

  1. The current text in TEXT_EDITOR window:

  1. The active (selected) UV-Map:

Working with MySQL database from Blender

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:

Binding to timeline frames

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.

Deleting nodes from compositing via script

To clear compositing window (completely remove all nodes from it), run the following code:

 

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.