How to install required packages to the Blender Python with pip

For add-ons developing, sometimes it is necessary to use packages that are not included in the core set of the Blender Python interpreter. Most often, the dependencies you need are included in the Python Package Index (PyPI) and can be installed to Blender through the Pip package management system.

The Pip Package Manager is already installed in Blender. However, Blender does not allow us to install the desired packages in a common way with the “pip install package_name” command.

Continue reading “How to install required packages to the Blender Python with pip”

How to rotate objects through the Blender Python API

For objects rotation, we can use the “rotation_euler” property. This property is a list of three items, each of them corresponds to the rotation angle around the X, Y, and Z-axis. The otation_euler[0] contains the rotation angle around the X-axis, rotation_euler[1] – around the Y-axis, and rotation_euler[2] – around the Z-axis. To rotate an object we must set a rotation angle to the appropriate field of the property.

For example, to rotate an active object around the X-axis to the 90 degrees angle we must execute the following command:

math.radians is used to convert degrees to radians.

How to switch between flat and smooth shading through the Blender Python API

The flat/smooth shading mode is regulated through the “use_smooth” property of each polygon of the mesh.

To enable smooth shading we need to set the “use_smooth” property of each mesh polygon to “True”.

For active object:

To enable flat shading – set the “use_smooth” property of each polygon to “False”.

To make new shading mode visible – force update mesh data:

Switching between coordinate systems

To switch from a global coordinate system to a local coordinate system of an object, we need to multiply the global coordinates by the inverted matrix of an object:

To switch from the local coordinate system of the object to the global coordinate system, we need to multiply the local coordinates by the matrix of an object:

How to make node connections in Blender 2.8 not straight, but curving as before

In Blender 2.8 node connectors in the “Shader Editor” window are straight by default, unlike earlier versions, where they bent curving. To return the usual connections bend, change the following settings:

  • Open the “Preferences” window
  • Switch to “Themes”
  • Expand the “Node Editor” tree branch
  • In the “Node Curving” field, set the value greater than 0. 0 means straight lines, the larger – the greater bend. A value of 4 corresponds to the bend that was in Blender 2.7x versions.

Edit Source

For those who want to know “how Blender works” to write their own scripts and add-ons, the developers have provided a very convenient option – the ability to view any element source code in a single click.

To see the source code of any element: open the “Text Editor” window; then simply click on the desired element with the right mouse button and select “Edit Source”.

Continue reading “Edit Source”