Executing operators with parameters
When making your own custom operators, sometimes it is necessary to pass them certain values – execute operator with parameters.
The passed parameter must be defined as an operator property.
When making your own custom operators, sometimes it is necessary to pass them certain values – execute operator with parameters.
The passed parameter must be defined as an operator property.
The UV-map is directly linked to the mesh through meshloops. We can use that to transfer the selection from the UV-map to the mesh.
To transfer the selection from the UV-map to the mesh, we need to cycle through the mesh polygons, check which meshloops are selected and select the corresponding vertices on the mesh itself.
To get a list of vertices from the vertex group by its name we can use the following code:
1 2 |
[vert for vert in bpy.context.object.data.vertices if bpy.context.object.vertex_groups['vertex_group_name'].index in [i.group for i in vert.groups]] # [bpy.data.meshes['Cube'].vertices[0], bpy.data.meshes['Cube'].vertices[1], ... |
Bezier curves are drawing by four points: two main points (p0, p1) and two handle points (p0_hr, p1_hl).
To add an additional point p2 to a curve at a moment t, with t changes from 0 to 1 and represents the ratio of the p2 point location to the total length of the curve, we need to do the following:
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.
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 quick node creation by their type.
Code by Skarn.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
class NodeTreeBuilder: def __init__( self , node_tree : bpy.types.NodeTree , x : float = -200 , y : float = -200 , delimeter : float = 300 ): self._x = x self._y = y self.tree = node_tree self.delimeter = delimeter self.purge_tree() def purge_tree(self): for node in self.tree.nodes: self.tree.nodes.remove(node) def add_node( self , node_type : str , node_name : str , column : int , row : int , node_descr : str = "" ): node = self.tree.nodes.new(node_type) node.name = node_name node.label = node_descr if node_descr else node_name node.location = (self.delimeter * column + self._x, -self.delimeter * row + self._y) return node |
With the Blender popularity growing, the number of add-ons created for it by third-party developers is growing too. A lot of high-quality professional add-ons are written for Blender now. Over time, the number of add-ons is becoming more and more. And on this wave aggregators appeared – programs and services independently searching for add-ons and allowing Blender users to install add-ons quickly, many at once, and bypassing add-on distribution channels selected by their authors. What caused a negative reaction of add-on developers.
How to protect your add-on from downloading through aggregatorsRead More »
The following command returns the 3D View areas list with enabled Local View mode:
1 2 3 |
[area for area in bpy.context.screen.areas if area.type =='VIEW_3D' and area.spaces[0].local_view] # [bpy.data.screens['Layout']...Area] |
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.
Changing objects visibility in the viewport and while renderingRead More »