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.

enter image description here


1 Answer 1


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.



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 # <=== UPDATE
            blend_filepath = os.path.splitext(blend_filepath)[0]

        self.filepath = blend_filepath + self.filename_ext

    return {'RUNNING_MODAL'}
  • $\begingroup$ This method is defined in the internal blender scripts..so they can’t be changed (or rather should not). do you mean I can overload this method in my addon class inheriting from this helper class and do whatever I want to do in it to set the file path ? Btw, I ended up ditching the helper class and just defining the invoke method in my class directly. $\endgroup$ Mar 9, 2021 at 1:54
  • $\begingroup$ Congratulations that was the idea. Thanks heaps for the feed-back. $\endgroup$
    – batFINGER
    Mar 9, 2021 at 4:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .