Skip to content

Instantly share code, notes, and snippets.

@jmpinit
Created May 24, 2023 15:00
Show Gist options
  • Save jmpinit/10dc4aac10545cf718abc9dafe683699 to your computer and use it in GitHub Desktop.
Save jmpinit/10dc4aac10545cf718abc9dafe683699 to your computer and use it in GitHub Desktop.
Copy the `material_index` attribute between identical meshes in Blender. Makes it possible to copy per-face material assignments between meshes.
import bpy
# Get the active object
active_obj = bpy.context.active_object
# Get all selected objects
selected_objs = bpy.context.selected_objects
# Check that active object is a mesh
if active_obj.type != 'MESH':
print("Active object is not a mesh")
else:
# Copy the material_index from each face of active object to the corresponding face of each selected object
for obj in selected_objs:
if obj.type == 'MESH':
for face in range(len(active_obj.data.polygons)):
obj.data.polygons[face].material_index = active_obj.data.polygons[face].material_index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment