Skip to content

Instantly share code, notes, and snippets.

@aaronjolson
Created July 3, 2021 19:21
Show Gist options
  • Select an option

  • Save aaronjolson/10d86bbae14e58842ba303c13693d8c3 to your computer and use it in GitHub Desktop.

Select an option

Save aaronjolson/10d86bbae14e58842ba303c13693d8c3 to your computer and use it in GitHub Desktop.
remove extra materials from all objects in a scene
import bpy
for obj in bpy.context.selected_editable_objects:
obj.active_material_index = 1
for i in range(1, len(obj.material_slots)):
bpy.ops.object.material_slot_remove({'object': obj})
for block in bpy.data.materials:
if block.users == 0:
bpy.data.materials.remove(block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment