Hehe looks like my work here is done, you're ready to troubleshoot your addon on your own :)
Just kidding, don't hesitate to post questions here if need be ;)
BTW custom_collection.items.clear
doesn't call the method, you have to use custom_collection.items.clear()
I personally think it's better UX wise to let the user delete specific items from a collection. You could modify your operator a bit by adding an index input
class CustomCollectionActions(bpy.types.Operator):
bl_idname = "custom.collection_actions"
bl_label = "Execute"
action: bpy.props.EnumProperty(
items=(
("add",) * 3,
("remove",) * 3,
),
)
index: bpy.props.IntProperty(default=-1)
def execute(self, context):
custom_collection = context.scene.custom_collection
if self.action == "add":
item = custom_collection.items.add()
if self.action == "remove":
if self.index < 0:
custom_collection.items.remove(len(custom_collection.items) - 1 )
else:
custom_collection.items.remove(index) # Be careful here we're not checking if this is a valid index, might throw an error
return {"FINISHED"}
and in your panel draw
method
def draw(self, context):
# a bunch of things
box = self.layout.box()
for i, item in enumerate(context.scene.custom_collection.items):
op = box.operator("custom.collection_actions")
op.action = "remove"
op.index = i
box.operator("custom.collection_actions").action = "add"
or something like that (not tested)
Here's an example of how I used a similar concept in a fork of the prj addon :