Detecting file import

I’m writing a blender script and I want to be able to detect when a mesh file like STL or OBJ is imported and then perform a series of operations on the imported objects. Ideally with a popup message before hand asking the user if they want to perform those operations or not.

Unfortunately I’ve been unable to find a solution that actually works except for creating my own importer with a WM operator where the user has to choose my custom importer which isn’t intuitive and means I would have to make one for every file format.

Does anyone have a good way to detect if a mesh file has been imported and can also perform actions on those imported objects?

There is no direct way to add a callback to the specific operators being executed.
Though you can hook to it by checking last executed operator in callback added to https://docs.blender.org/api/current/bpy.app.handlers.html#bpy.app.handlers.depsgraph_update_post, then if it’s one of the import operators you’d need to find what objects were imported which means you need to always keep a list of objects prior to import. But depsgraph updates occur very often, so it might be an overkill.

Another option, if your import operators are Python based, then you can add a wrapper to their .execute and do stuff directly after their execution.

Ok this is what I also was seeing but I thought there may be something I was missing. I was hoping to be able to do it without extra user input but sounds like that’s not possible. Sounds like a custom importer is what I need. Thanks for the info!