acoolrocket

Blender - Copy material to selected (whilst retaining material slots)

Oct 13th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import bpy
  2.  
  3. # Get the active object (the source)
  4. source = bpy.context.active_object
  5. if not source:
  6. print("No active object selected.")
  7. else:
  8. # Get the active material from the active slot
  9. active_mat = source.active_material
  10. if not active_mat:
  11. print(f"{source.name} has no active material.")
  12. else:
  13. # Apply to all selected objects except the source
  14. for obj in bpy.context.selected_objects:
  15. if obj == source:
  16. continue
  17. if not obj.material_slots:
  18. print(f"{obj.name} has no material slots, skipping.")
  19. continue
  20.  
  21. # Assign the same material to all slots, without changing slot count
  22. for slot in obj.material_slots:
  23. slot.material = active_mat
  24.  
  25. print(f"Applied {active_mat.name} to all slots of {obj.name}.")
Add Comment
Please, Sign In to add comment