2
$\begingroup$

i created a custom blender ui. i know that normally we should register multiple panel and sub-panel but i decided to do things differently.

my UI is based on bool properties, like this below

enter image description here

prop stored in addon preferences

class SCATTER_AddonPref(AddonPreferences):
    bl_idname = __name__
    addon_prefs = bpy.context.preferences.addons[__name__].preferences

    scatter_sliders_display          : BoolProperty(name="",description="",default=False) 
    scatter_sliders_vgroup           : BoolProperty(name="",description="",default=False) 
    scatter_sliders_curv_is_open     : BoolProperty(name="",description="",default=False) 
    scatter_sliders_curv_adv_is_open : BoolProperty(name="",description="",default=False) 
    scatter_proxy_is_open            : BoolProperty(name="",description="",default=False)

and this is how i use it in the ui

layout.prop(addon_prefs,'scatter_camera_is_open',text="bla category",emboss=False,icon='BLENDER')
if addon_prefs.scatter_camera_is_open:
    layout.label(text="blablabla")

i think it is a really nice method. i already saw this used in many many case, but the problem as we saw in the gif is that it leave a trace in the undo history.

so is there's a way to avoid this or am i screwed ? anyhow i could ignore ctrl z with this specific property ? for example, is it possible to create an operator that will toggle thoses addon pref on/off and will not show up in the history at all ?

$\endgroup$
0
$\begingroup$

if i wisely use an operator that dont have 'UNDO' in its bl_option it can work easely.


class SCATTER_OT_panel_toggle(bpy.types.Operator):
    bl_idname      = "scatter.test"
    bl_label       = ""
    bl_description = ""

    pref : bpy.props.StringProperty()
    def execute(self, context):
        pref=self.pref

        addon_prefs = bpy.context.preferences.addons[__name__].preferences

        if eval("addon_prefs."+pref)== True:
            exec("addon_prefs."+pref +"= False")
        else:
            exec("addon_prefs."+pref +"= True")
        return {'FINISHED'}

example in code ui


        row.operator(SCATTER_OT_panel_toggle.bl_idname,text=na,emboss=False,icon=ixon).pref = "scatter_radar_is_open"

|improve this answer|||||
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.