Color mask by scene materials
To quickly create a color mask by materials, assigned to the scene objects, for post-processing
you can use the following script:
To quickly create a color mask by materials, assigned to the scene objects, for post-processing
you can use the following script:
When developing add-ons it is often necessary to give an ability to set a number of parameters that affect the whole add-on work to the user. For example, the user can specify a directory for saving/loading files, set some default variables or switch between add-on modes. Of course, the interface for setting such parameters can be placed in the add-on panel, but it is better to place it in a separate add-on preferences panel, which is located in the “Preferences” window under the add-on installation panel.
The main advantage of the add-on preferences is that they don’t reset when Blender restarts. The user does not need to configure the add-on preferences each time, it’s enough to set the necessary parameters once, personalizing the add-on for convenient work.
Let’s create an add-on and define a parameter, placing it in the add-on preferences panel.
To find what Python interpreter version is used in current Blender version type the following commands in Python Console window in Blender:
1 2 3 4 |
import sys print(sys.version_info) # sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0) |
It means that the version of Python used in Blender is 3.7.0.
To make it more readable type the following command:
1 2 |
print('.'.join(map(str, sys.version_info[:3]))) # 3.7.0 |
or with full info:
1 2 |
print(sys.version) # 3.7.0 (default, Aug 26 2018, 16:05:01) [MSC v.1900 64 bit (AMD64)] |
In the latest version 2.8 of Blender developers have made many changes in API, so all the scripts and add-ons written for earlier Blender versions (2.7 and below) have stopped working. To run your add-ons in the new Blender 2.8, you need to port them – correct their code to work properly with the new Blender API.
To enable your add-on in Blender 2.80 you have to make the following changes in code:
Blender has its own built-in text editor for writing scripts and add-ons, but it’s much convenient to develop them in external IDEs that provide the user with more features such as autocomplete, syntax highlighting, integration with version control systems and other tools that make development faster and easier.
One of these IDEs is Visual Studio Code from Microsoft. This is a free universal environment that supports development with various programming languages, including the Blender API language – Python.
Using Microsoft Visual Studio Code as external IDE for writing Blender scripts/add-onsRead More »
In general, the “loop” is usually a sequential selection of several points, edges or polygons of a mesh.
However, there is an element in the mesh structure, which is also called a “loop”. It is a combination of one vertex with one edge of the mesh. Let’s try to learn what these “loops” are for.
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.
How to pass command line arguments to a Blender python script or add-onRead More »
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.
Let’s create our own radio button switcher.
Creating radio buttons in the Blender add-ons interfaceRead More »
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:
1 |
hasattr(bpy.types, bpy.ops._operator_bl_idname_.idname()) |
Where:
_operator_bl_idname_ – the text value of the bl_idname operator property.
For example for an operator:
1 2 3 4 5 6 |
class TestOperator(bpy.types.Operator): bl_idname = 'test.operator' bl_label = 'Test operator' def execute(self, context): pass |
the command will look like this:
1 |
hasattr(bpy.types, bpy.ops.test.operator.idname()) |
To start working every Blender add-on must be registered by setting up the checkbox before add-on name in the User Preferences window – Add-ons page.
To programmatically find out if the required add-on is registered, run the following command:
1 |
'add-on_name' in the file bpy.context.user_preferences.addons |
Where:
add-on_name – the name of the add-on file (without the .py extension) or the name of the add-on package, if it was installed from the package.