2
$\begingroup$

I have object with 600 material slots in exact order(to maintain the material IDs when exporting to 3Ds max via fbx). But sometimes the materials are duplicated and I get eg 1200 material slots in one object (eg if I merge two objects with different material names). In this case I need to remove last 600 material slots, but it's quite impractical. But unfortunately I have no knowledge about python scripting and its syntax. So, can someone help me with creating some simple script? The only thing I found out is that I probably need to call commands like "bpy.context.object.active_material_index = 599-1199" or repeat command for delete last material slot 600 times I tried to use Material Utilities for resolve my problem, but unfortunately without success.

$\endgroup$

1 Answer 1

4
$\begingroup$

This script will delete the n_to_remove last material slots of your active object in reversed order (from the last material slot down).

import bpy
o  = bpy.context.object
ms = o.material_slots

n_to_remove = 3 # Change this number to decide how many material slots to remove
for i in range( len(ms) - 1, len(ms) - n_to_remove - 1, -1):
    o.active_material_index = i
    bpy.ops.object.material_slot_remove()
$\endgroup$
1
  • $\begingroup$ Thank you very much, that's exactly what I wanted. $\endgroup$ Oct 30, 2019 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .