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):
pass
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
row.label(text="Bevel")
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")
else:
mm.new(name="Bevel", type='BEVEL')
mm["Bevel"].use_clamp_overlap = False
return {'FINISHED'}
classes = (
DC_MT_popup_star,
)
register, unregister = bpy.utils.register_classes_factory(classes)
if name == "main":
register()
DC_OT_po...since class type is operator. Does that help? – brockmann Jun 20 '20 at 19:23mm... above would be something likebm = ob.modifiers.get("Bevel")and to test if it does not existif bm is None:and then add a new onebm = ob.modifiers.new(...)then will belayout.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 – batFINGER Jun 21 '20 at 03:00