Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
Created June 12, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taikomatsu/a41d2a351017f250d2d87801eacd6ddc to your computer and use it in GitHub Desktop.
Save taikomatsu/a41d2a351017f250d2d87801eacd6ddc to your computer and use it in GitHub Desktop.
Assign a material to selected objects in Blender
# reference:
# https://blender.stackexchange.com/questions/23433/how-to-assign-a-new-material-to-an-object-in-the-scene-from-python
import bpy
mat = bpy.data.materials.get('my_material')
for o in bpy.context.selected_objects:
if o.data.materials:
ob.data.materials[0] = mat
else:
o.data.materials.append(mat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment