Help With Prepopulating Collection List

Hi, I’ve been working on a Blender plugin for some time now, the plugin itself to serve as a level editor for a game I’ve been modding utilizing Blender’s workflow. Of course, this requires a way to select an object to add, and because large enums don’t work too well, I opted to use a collection list to hold all of the 600+ entries. This works fine and all, but the issue comes with populating the list itself, where I can’t seem to find a straight-forward way.

Currently, I use an operator to do so, but this feels a bit hacky and I would like to imagine there is a better way. The operator code is as follows:

def execute(self, context):
    for data in OBJECTS_LIST.values():
        item = context.scene.object_list.add()
        item.name = data.get("name", "")
        item.model = data.get("model", "")
        item.key = data.get("key", "")
    return {'FINISHED'}

Why you consider it hacky?

I would like a more elegant, function contained solution opposed to calling an operator on registration, as that can be a bit tricky to keep track of when reloading scenes. I’ll continue with that method for now, I guess

If this collection is suppose to track objects existing in Blender it is kind of tricky. You can populate your collection at blender file load with https://docs.blender.org/api/current/bpy.app.handlers.html#bpy.app.handlers.load_post but there is no direct way to subcribe to new objects created. You can use https://docs.blender.org/api/current/bpy.app.handlers.html#bpy.app.handlers.depsgraph_update_post or timers but that’s usually an overkill.

Thank you so much for the reply! The collection is meant to store a predefined list of items, basically serving as an enum but without the issues that lengthy enums run into. Notably enums lack a scroll bar and start creating new columns

Maybe search argument for StringProperty can help - https://docs.blender.org/api/current/bpy.props.html#bpy.props.StringProperty