I would like to add an addon preference setting to the user preferences for my addon. I would like to have a list there where you can add and remove things (at first only Strings).
This sets it up:
class AddonPref(bpy.types.AddonPreferences):
bl_idname = __package__
FileName : StringProperty()
presets_List = ["hi", "bye"]
addRemove : EnumProperty(
items = [('one', 'add', ''),
('two', 'remove', '')
])
def draw(self, context):
layout = self.layout
box = layout.box()
split = box.split()
col = split.column(align = True)
col.prop(self, "FileName")
row = col.row()
row.prop(self, "addRemove", expand = True)
col.operator("presets.addremove")
for x in self.presets_List:
col.label(text=x)
And now I would like to edit the list with an operator (I already have got the add/Remove Enum and the FileName String properties. Only thing missing: the operator
class PresetsADDREMOVE(bpy.types.Operator):
bl_idname = "presets.addremove"
bl_label = "resets func"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
preferences = context.preferences
addon_prefs = preferences.addons[__package__].preferences
presets = addon_prefs.presets_List
if addon_prefs.addRemove == 'one':
presets.append(addon_prefs.FileName)
else:
presets.remove(addon_prefs.FileName)
return {'FINISHED'}
This operator does work correctly.Though, I have got one big problem. The list is not the same in other blend files. It does not behave as an addon preference "property".
So what would I have to do to fix this problem? Thanks for the help! :D