I am traying to make a popup menu that will add a modifier if the object has none and then draw the menu, or just draw it if the modifier is already on it.

But i am not sure how to go about it, the script i have is working, but it only adds the modifier after i close the panel. Tried creating another class just for the operation but didn't work also.

import bpy

class DC_MT_popup_star(bpy.types.Operator):
    bl_idname = "popup.dc_star"
    bl_label = "Str Popup"
    bl_space_type = "VIEW_3D"

    def execute(self, context):

    def invoke(self, context, event):
        wm = context.window_manager       
        return wm.invoke_popup(self, width=200)
    def draw(self, context):
        layout = self.layout
        row = layout.row()
        split = layout.split()
        col = split.column()

        ob = context.object
        mm = ob.modifiers
        if "Bevel" in ob.modifiers:           
            col.prop(mm["Bevel"], "width", text= "Offset")
            col.prop(mm["Bevel"], "segments", text= "Segments")
            col.prop(mm["Bevel"], "angle_limit", text= "Angle")
            col.prop(ob.data, "auto_smooth_angle", text="Smooth")
            col = split.column()
            col.prop(mm["Bevel"], "limit_method", text= "")
            col.prop(mm["Bevel"], "use_clamp_overlap", text= "Clip")
            col.prop(ob.data, "use_auto_smooth", text="Auto Smooth")
            mm.new(name="Bevel", type='BEVEL')
            mm["Bevel"].use_clamp_overlap = False
            return {'FINISHED'}

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

if __name__ == "__main__":
  • 2
    $\begingroup$ You can either add an invoke method: blender.stackexchange.com/a/19431/31447 or add a second operator and call this one while execution, not sure what's better in your case. Notice your class name should be DC_OT_po... since class type is operator. Does that help? $\endgroup$ – brockmann Jun 20 '20 at 19:23
  • $\begingroup$ @brockmann Does exactly what i wanted, thank you!, i thought invoke was just for ui stuff. But just so i know.. when you say that it can be done with a second operator, this new operator would still have to be reference on the invoke to be triggered first than the panel draw? $\endgroup$ – Udjani Jun 20 '20 at 20:28
  • $\begingroup$ @brockmann Could you add a short answer? Or could we pass this off as a duplicate? $\endgroup$ – Leander Jun 20 '20 at 20:53
  • 1
    $\begingroup$ Only draw properties in a draw method. Re my previous comment with mm ... above would be something like bm = ob.modifiers.get("Bevel") and to test if it does not exist if bm is None: and then add a new one bm = ob.modifiers.new(...) then will be layout.prop(bm, "width") This is known as "by reference" (regardless of name) rather "by key" ob.modifiers["key"]. Blender automatically appends numbers if two objects have same name, eg a second bevel modifier would be given the name "Bevel.001" if "Bevel" is taken. To be sure [m for m in ob.modifiers if m.type == 'BEVEL'] is $\endgroup$ – batFINGER Jun 21 '20 at 3:00
  • 1
    $\begingroup$ a list of all bevel modifiers on the object. $\endgroup$ – batFINGER Jun 21 '20 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.