From bd738026fafdf55ee01687f2bf6bdf08ea2e39e1 Mon Sep 17 00:00:00 2001 From: formcore Date: Wed, 26 Oct 2022 03:06:21 +0100 Subject: [PATCH] FIX: Not all selected are processed --- __init__.py | 2 +- operators.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 1a565cf..59d47e1 100644 --- a/__init__.py +++ b/__init__.py @@ -20,7 +20,7 @@ bl_info = { "name" : "Simple Material Flattener", - "author" : "Irssss sssssson", + "author" : "Iron", "description" : "", "blender" : (3, 3, 1), "version" : (0, 0, 1), diff --git a/operators.py b/operators.py index e075864..d7fb866 100644 --- a/operators.py +++ b/operators.py @@ -18,6 +18,8 @@ class SMF_OT_flatten_materials(Operator): # bpy.ops.object.material_slot_select() # bpy.ops.object.mode_set(mode='EDIT') (mode='OBJECT) # bpy.types.ShaderNodeTexImage() ??? + # bpy.ops is expensive and should be avoided: re-assign verts without ops? + # view a verts mat? or a mats verts? selected_objects = [i for i in bpy.context.selected_objects] store_selected_objects = selected_objects.copy() @@ -27,11 +29,13 @@ class SMF_OT_flatten_materials(Operator): bpy.ops.object.select_all(action='DESELECT') for o in selected_objects: + bpy.context.view_layer.objects.active = o imageMaterialNames = {} print("gettings materials from %s" % o.name) # select this object o.select_set(True) - # switch to edit mode + # switch to edit Mode + bpy.ops.object.material_slot_remove_unused() bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='DESELECT') @@ -47,6 +51,7 @@ class SMF_OT_flatten_materials(Operator): if not last_image: last_image = image if last_image == image: + print("add to selection") o.active_material_index = slot.slot_index bpy.ops.object.material_slot_select() continue