To get material and its properties with Python API in Blender
Environment
Blender 2.83 Windows 10
Methods
How to get material
Method1. Get active material
Active material is the material currently selected in the material slot. If you select a face, the active material changes to the material assigned the selected face.
The following is the script to get active material of an object named “Cube”.
Method2. Get material slots and select one of them
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import bpy
obj = bpy.data.objects["Cube"]
material_slots = obj.material_slots
for m in material_slots:
material = m.material
print("slot", m, "material", material)
# output is material slot and material
# slot <bpy_struct, MaterialSlot("Material")> material <bpy_struct, Material("Material")>
# slot <bpy_struct, MaterialSlot("Material2")> material <bpy_struct, Material("Material2")>
# slot <bpy_struct, MaterialSlot("Material3")> material <bpy_struct, Material("Material3")>
import bpy
obj = bpy.data.objects["Cube"]
material_slots = obj.material_slots
for m in material_slots:
material = m.material
print("slot", m, "material", material)
# output is material slot and material
# slot <bpy_struct, MaterialSlot("Material")> material <bpy_struct, Material("Material")>
# slot <bpy_struct, MaterialSlot("Material2")> material <bpy_struct, Material("Material2")>
# slot <bpy_struct, MaterialSlot("Material3")> material <bpy_struct, Material("Material3")>
import bpy
obj = bpy.data.objects["Cube"]
material_slots = obj.material_slots
for m in material_slots:
material = m.material
print("slot", m, "material", material)
# output is material slot and material
# slot <bpy_struct, MaterialSlot("Material")> material <bpy_struct, Material("Material")>
# slot <bpy_struct, MaterialSlot("Material2")> material <bpy_struct, Material("Material2")>
# slot <bpy_struct, MaterialSlot("Material3")> material <bpy_struct, Material("Material3")>
You can get a slot with index or key (material name). The order of slots follows the order on material slot UI.
You can change the attributes of the object from “Object Properties” tab. The color can be set in the “Visibility” menu.
How to display the object color
1. Change the object color
2. Change the renderer into “Workbench”
The Workbench Engine is a render engine optimized for fast rendering during modeling and animation preview.
from Introduction of workbench in Blender2.91 Manual
3. Set the color “Object”
You can select colors that the Workbench uses to render objects from single, Object, Material, Random, Vertex and Texture. See “Color” page of workbench in Blender2.91 Manual for details.
To understand Blender keymap related to “ActionZone”.
Environment
Blender2.83 Windows10
How to see the current keymap settings
Edit > Preferences > Keymap
You can see actions and assigned keymaps. There are “ActionZone” in short cut keys.
What is ActionZone?
I couldn’t find any official documentation, but I think ActionZone means the each windows of editor.
Move the cursor to the upper right corner then the cross cursor will appear. When the cross cursor is displayed, you can handle “ActionZone”.
Example of usages
ActionZone (dragging cross cursor): split and join the area Shift + ActionZone (dragging cross cursor) : Duplicate area into new window Ctrl + ActionZone (dragging cross cursor) : Swap area
In this scene there are 3 materials that has 3 colors, red, green and blue. The red material and green material are set to objects.
The blue material is not used now, but how to delete unnecessary material, the blue one?
Method 1. Find the material from “Blender File” and delete it.
Change the Display Mode of the Outliner into “Blender File”.
Open Material tab and right-click the material to delete.
Method 2. delete materials in “Orphan Data”.
Change the Display Mode of the Outliner into “Orphan Data”. The items displayed in the display mode “Orphan Data” are items that are not used or connected to any other items.
Open Material tab and right-click the material to delete.
Method 3. Reload the blender file.
Save the file and reopen it. All orphan data are automatically deleted when the file is reloaded.