API

How to get vertices from Vertex Group by its name

To get a list of vertices from the vertex group by its name we can use the following code:

 

Fake-bpy-module

Code autocomplete greatly simplifies writing scripts or developing add-ons for Blender. One of the best autocomplete modules for today is developed by Nutti. Last updated 20190718.

The project is hosted on the author’s GitHub: https://github.com/nutti/fake-bpy-module

The modules are distributed via pip or as a pre-generated-modules. Author also provides a module generator with which you can assemble autocomplete modules yourself.

Decorators for node tree updation delay

When we create a field on the add-on interface panel, the value of which changes something in the node tree, each time the user changes the field value the node tree recompiles. If the user changes the value in that field by holding and moving the mouse, too frequent node tree recompilation will cause Blender to hangs.

This problem can be solved using decorators for deferred updating of the node tree.

Code by Skarn.

Class for creating nodes by type

Class for quick node creation by their type.

Code by Skarn.

How to detect if Local View is on in 3D View window

The following command returns the 3D View areas list with enabled Local View mode:

 

Changing objects visibility in the viewport and while rendering

The easiest way to hide and show rendering objects is to assign animation keys to them. To do this, move the cursor over the eye icon (visibility in the viewport) or camera (visibility when rendering) in the Outliner window, press the “i” key and then manage the created condition in the Graph Editor like the ordinary animation keys.

But this method is not always available. For example, we cannot assign visibility animation keys for collections, Blender will generate errors like:

“hide_viewport” property cannot be animated

or

“hide_render” property can not be animated

However, using the Blender Python API, we can control the visibility of such objects.

Blender autocomplete modules

Nutti, the author of the “fake-bpy-modules” project, has made the installation of the Blender Python API autocomplete modules through the pip platform. Pip installation is faster and easier, but sometimes we just need to copy the autocomplete modules to our project but now they are not included in the Nutti’s GitHub.

Copies of the autocomplete modules for Blender versions 2.79 and 2.80 can be downloaded directly from here: https://github.com/Korchy/blender_autocomplete

 

How to get global vertex coordinates

To get the vertex coordinates in the scene global coordinate system when the object’s scale was not applied, we need to multiply the local vertex coordinates by the object world transformation matrix: