1

I am traying to make a mirror modifier popup, and i'ts working for the most part, but is saving the ''previous operations''

When i call it the first time it works as intended, i can choose the axis that it will mirror, but after if i call it again and press any button it will apply all the settings i have choosen previously. Can i reset it everytime or something?.

Also, isn't there any better way to make modifiers popup instead of having to make all of it manually?


class DC_MT_popup_mirror(bpy.types.Operator):
    bl_idname = "popup.dc_mirror"
    bl_label = "Mirror Popup"
    bl_space_type = "VIEW_3D"
def execute(self, context):
   pass


def invoke(self, context, event):
    wm = context.window_manager       
    return wm.invoke_popup(self, width=100)
    return {'FINISHED'}    


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

    layout.label(text="Mirror")

    row = layout.row()
    row.operator('3dview.dc_mirror', text= "X").x_axis = True
    row.operator('3dview.dc_mirror', text= "Y").y_axis = True
    row.operator('3dview.dc_mirror', text= "Z").z_axis = True


    return {'FINISHED'}


class DC_OT_mirror_add(bpy.types.Operator): bl_idname = '3dview.dc_mirror' bl_label = 'Mirror Axis'

x_axis : bpy.props.BoolProperty(name = "X Axis", default = False)
y_axis : bpy.props.BoolProperty(name = "Y Axis", default = False)
z_axis : bpy.props.BoolProperty(name = "Z Axis", default = False)


#pos_axis :bpy.props.IntProperty(name = "X Axis", default = -1)

def execute(self, context):
    ob = context.object
    #x = x_axis        


    if "dcMirror" not in ob.modifiers:
        ob.modifiers.new(name="dcMirror", type='MIRROR')
        ob.modifiers["dcMirror"].show_on_cage = True
        ob.modifiers["dcMirror"].use_axis[0] = False
        ob.modifiers["dcMirror"].use_clip = True


    if self.x_axis:
        ob.modifiers["dcMirror"].use_axis[0] = self.x_axis
        ob.modifiers["dcMirror"].use_bisect_axis[0] = self.x_axis


    if self.y_axis:  
        ob.modifiers["dcMirror"].use_axis[1] = self.y_axis
        ob.modifiers["dcMirror"].use_bisect_axis[1] = self.y_axis
        ob.modifiers["dcMirror"].use_bisect_flip_axis[1] = self.y_axis

    if self.z_axis:  
        ob.modifiers["dcMirror"].use_axis[2] = self.z_axis
        ob.modifiers["dcMirror"].use_bisect_axis[2] = self.z_axis            

    return {'FINISHED'}    


classes = ( DC_MT_popup_mirror, DC_OT_mirror_add,
) register, unregister = bpy.utils.register_classes_factory(classes)

if name == "main": register()```

Udjani
  • 117
  • 4
  • IMO would get out of habit of collection[name] in blender. Above could be mm = ob.modifiers.get("dcMirror") and if this is None then mm = ob.modifiers.new(name="dcMirror", type='MIRROR') and then mm.setting = value Code will look cleaner, and will only have to type "mm" (or whatever name is chosen) rather than ob.modifiers["foo"] each time. – batFINGER Jun 20 '20 at 03:10

0 Answers0