LODs creation: inverting mesh name issue

Hi there,

i’m starting to create an addon that generate3 levels of LODs with3 specific names _high _low an _ proxiy suffixes from a selected mesh by hitting a single button in the Data Object Properties panel.

  1. script works very well
  2. simple operator works very well too
  3. When i copy/paste the simple operator in the Ui panel template it generates 3 meshes bu invert the name of _high and _low Meshs. Could you help me please to find a solution?

Many thanks

find attched my .blend file
here is the code:

import bpy

def main(context):

def main(context):
        

for obj in bpy.context.selected_objects:
    obj.name += '_high'
    obj.data.name = obj.name

#copy high def to LOW def
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={“linked”:False, “mode”:‘TRANSLATION’}, TRANSFORM_OT_translate={“value”:(0, 0, 0), “orient_type”:‘GLOBAL’, “orient_matrix”:((1, 0, 0), (0, 1, 0), (0, 0, 1)), “orient_matrix_type”:‘GLOBAL’, “constraint_axis”:(False, False, False), “mirror”:True, “use_proportional_edit”:False, “proportional_edit_falloff”:‘SMOOTH’, “proportional_size”:1, “use_proportional_connected”:False, “use_proportional_projected”:False, “snap”:False, “snap_target”:‘CLOSEST’, “snap_point”:(0, 0, 0), “snap_align”:False, “snap_normal”:(0, 0, 0), “gpencil_strokes”:False, “cursor_transform”:False, “texture_space”:False, “remove_on_cancel”:False, “release_confirm”:False, “use_accurate”:False, “use_automerge_and_split”:False})

#rename mesh as _low
for obj in bpy.context.selected_objects:
obj.name = obj.name.replace("_high","_low")
obj.name = obj.name[:-4]

bpy.ops.object.modifier_add(type='DECIMATE')
bpy.context.object.modifiers["Decimate"].ratio = 0.005
bpy.ops.object.modifier_apply(modifier="Decimate", report=True)

obj.data.name = obj.name.replace("_high","_low")

#copy low def to proxy
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={“linked”:False, “mode”:‘TRANSLATION’}, TRANSFORM_OT_translate={“value”:(0, 0, 0), “orient_type”:‘GLOBAL’, “orient_matrix”:((1, 0, 0), (0, 1, 0), (0, 0, 1)), “orient_matrix_type”:‘GLOBAL’, “constraint_axis”:(False, False, False), “mirror”:True, “use_proportional_edit”:False, “proportional_edit_falloff”:‘SMOOTH’, “proportional_size”:1, “use_proportional_connected”:False, “use_proportional_projected”:False, “snap”:False, “snap_target”:‘CLOSEST’, “snap_point”:(0, 0, 0), “snap_align”:False, “snap_normal”:(0, 0, 0), “gpencil_strokes”:False, “cursor_transform”:False, “texture_space”:False, “remove_on_cancel”:False, “release_confirm”:False, “use_accurate”:False, “use_automerge_and_split”:False})

#rename mesh as _low
for obj in bpy.context.selected_objects:
obj.name = obj.name.replace("_low","_proxy")
obj.name = obj.name[:-4]

#create point clouds
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action=‘SELECT’)
bpy.ops.mesh.delete(type=‘EDGE_FACE’)
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type=‘VERT’)
bpy.ops.machin3.vertex_mode()
bpy.ops.mesh.select_random(seed=2)
bpy.ops.mesh.select_random(percent=70, seed=2)
bpy.ops.mesh.delete(type=‘VERT’)
bpy.ops.object.editmode_toggle()

obj.data.name = obj.name.replace("_low","_proxy")

class SimpleOperator(bpy.types.Operator):
“”“Tooltip”""
bl_idname = “object.simple_operator”
bl_label = “GENRERATE LODs”

def execute(self, context):
    main(context)
    return {'FINISHED'}

class LayoutDemoPanel(bpy.types.Panel):
“”“Creates a Panel in the scene context of the properties editor”""
bl_label = “Layout Demo”
bl_idname = “SCENE_PT_layout”
bl_space_type = ‘PROPERTIES’
bl_region_type = ‘WINDOW’
bl_context = “data”

def draw(self, context):
    layout = self.layout

    scene = context.scene

    
    # Big render button
    layout.label(text="Settings:")
    row = layout.row()
    row.scale_y = 3.0
    row.operator("object.simple_operator")

def register():
bpy.utils.register_class(SimpleOperator)
bpy.utils.register_class(LayoutDemoPanel)

def unregister():
bpy.utils.unregister_class(SimpleOperator)
bpy.utils.unregister_class(LayoutDemoPanel)

if name == “main”:
register()