Selecting scene camera with shortcode
It can be difficult to quickly find and select the scene camera from many other objects in large scenes. However, we can make an operator and assign its call to a hotkey to find the scene camera in a moment.
It can be difficult to quickly find and select the scene camera from many other objects in large scenes. However, we can make an operator and assign its call to a hotkey to find the scene camera in a moment.
To hide an object in the 3D Viewport window for the current scene we use the “object.hide_view_set” operator, which calls when we clicking the icon with an “eye” in the outliner. However, to hide the object in the viewport for all scenes of the project at once (clicking on the icon with the “monitor” image) a special operator is not provided. We can make it ourselves.
Operators for globally hiding objects in all project scenesRead More »
The Blender API recommends creating custom object properties through the predefined bpy.props classes. For example, the bpy.props.IntProperty class is used to add an integer property. These properties are convenient, work well, and are easy to display on the user interface panels.
To apply all transformations to an object, all its vertices must be multiplied by its global matrix, the matrix itself must be made identity.
To apply all transformations to the active mesh, we need to execute the following:
1 2 3 4 5 6 7 |
import bpy obj = bpy.context.object matrix = obj.matrix_world.copy() for vert in obj.data.vertices: vert.co = matrix @ vert.co obj.matrix_world.identity() |
In Blender API there is a module that we can use to track the changes of any object’s properties available through the Python API. This module names “Message Bus”.
Let’s look at how we can make an event handler function to track changes to a property. For example – the location of the 3D cursor.
A simple script for transferring the origin of all selected objects to the origin of the active object.
Since Blender 2.9, the ability to assign color tags has been added for collections. Collection with such tag is displaying in a specific color in the outliner.
The collection color tag value is stored in its “color_tag” property. To change the color label of a collection, we need to assign a certain value to this property.
For example, to mark the current active collection in green:
1 |
bpy.context.collection.color_tag = 'COLOR_04' |
Setting colors for Blender collections with the Python APIRead More »
To add a new slot to the material slots for an object:
The “wm.context_toggle” operator is used to toggle checkboxes in the Blender interface. We can configure fast switching of any checkboxes in any windows and panels with this operator.
As an example, let’s configure the checkbox which enables/disables displaying the viewport wireframe.
To get the currently active brush in “Sculpt” mode with the Blender Python API we can use the following command:
1 2 3 |
bpy.context.tool_settings.sculpt.brush # bpy.data.brushes['SculptDraw'] |