Using the FileBrowser interface window to opening and saving files

In scripts and add-ons for importing-exporting files with formats that are not supported in Blender by default, we must give the user an ability to select files using the “FileBrowser” interface.

To open the file browser window, and after the user selects the necessary file, to return the path to it, we need to use the “ImportHelper” and the “ExportHelper” classes.

Continue reading “Using the FileBrowser interface window to opening and saving files”

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 to the view from camera throug the python API

To switch to the view from the active camera we can execute the following command:

This operator works in the toggle mode, so the next executing of the same command returns the view to the previous state.

Continue reading “Switching to the view from camera throug the python API”

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.

Where did the code completion in the python console in Blender 2.82 disappear

In Blender 2.81 and earlier, you could see the possible code completion by pressing “ctrl + space” in the python console. This key-shot shows nothing in Blender 2.82.

Code autocompletion in the python console was not removed in 2.82, it was moved to the “tab” key.

User interface elements alignment by columns

Interface elements in custom user panels often do not correspond to each other in size. As a result – the overall panel layout does not look beautiful. As an example, let’s create a custom panel and place an operator button and an input text field on it.

Can we make it more accurate?

Continue reading “User interface elements alignment by columns”

How to get all collectons list

To get a list of collections with all internal collections, we can use the following function:

Continue reading “How to get all collectons list”

Global materials override for the Blender EEVEE render engine

Some times we need to make a render of the scene with the single material, for example, for clay or wireframe renders. Blender has the global materials override option for the Cycles render engine in the “View Layer Properties” – “Override” but not for the EEVEE render engine.

Quick materials override for the EEVEE rendering engine can be made with a small script, as shown in the following video:

Script and video by Vitaly Sokol.

Continue reading “Global materials override for the Blender EEVEE render engine”

How to enable gradient background in the viewport window

To enable gradient background in the “3D View” window you need:

  • open the “Preferences” window
  • press the “Themes” button
  • in the “3D View” – “Theme Space” -” Gradient Colors” section on the “Use Gradient” checkbox
  • and tune the gradient colors “Gradient HighOff” (top color) and “Gradient Low” (bottom color)
  • press the “Save Preferences” button to save changes