Python

How to get a list with all possible values of an EnumProperty

To correctly set values to an EnumProperty type we need to know all its possible entries.

If we try to set a value to an EnumProperty that is out of its available variants, Blender will throw an error:

TypeError: bpy_struct: item.attr = val: enum “xxx” not found in (‘value_001′, value_002’, …)

where:

xxx – the value we tried to set to an EnumProperty

value_001, value_002, … – possible EnumProperty values

How to move cursor to vertex

To translate cursor to the desired mesh vertex execute the following code:

Attention to the multiplication order – world matrix should be left.

How to link a new object to a scene in Blender 2.80 Python API

In Blender 2.79 Python API we can add a new object to a scene with:

If we try to do this in Blender 2.80, it throws an error:

‘bpy_prop_collection’ object has no attribute ‘link’

In Blender 2.80 API new objects mast be linked not to the scene, but to the scene collections:

To link a new object to the active scene collection:

To link a new object to the collection by its name:

 

How to move the cursor to the active strip start/end position in Blender VSE

To move the cursor to the start position of the active strip in Blender VSE:

To move the cursor to the end position of the active strip:

 

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.