How do I make an export addon pre-populate filename with name of the selected object? I’m creating an export/import add-on (similar to STL import/export add-on) and I would like the suggested filename in the file browser to take the name of the currently selected object in the scene or a generic filename if multiple objects are selected. My add-on uses the bpy_extras.io_utils’s ExportHelper.
In the example below, for a new, unsaved blend file, the default filename is untitled.sur (sur is the extension the file exported by my addon). I would like this name to be “Icosphere.sur” since the object “Icosphere” is selected in the scene.
Set in the invoke method.
As noted in these answers the IO helpers have invoke and check methods that are doing some things behind the scenes.
https://blender.stackexchange.com/a/198924/15543
https://blender.stackexchange.com/a/207665/15543
The export helper invoke method, that if not set sticks in the name Untitled, simply change this to that of the context object.
def invoke(self, context, _event):
    import os
    if not self.filepath:
        blend_filepath = context.blend_data.filepath
        if not blend_filepath:
            blend_filepath = context.object.name # &lt;=== UPDATE
        else:
            blend_filepath = os.path.splitext(blend_filepath)[0]

        self.filepath = blend_filepath + self.filename_ext

    context.window_manager.fileselect_add(self)
    return {'RUNNING_MODAL'}