Have a look into the templates (Text Editor -> Templates -> Python -> Operator Export). Straight after the user has selected the location and filename, the execute method of the operator is called. What do operator methods do? (poll, invoke, execute, draw & modal)
Complete example how to invoke the file dialog and write a .bat file according to the wikipedia entry: https://en.wikipedia.org/wiki/Batch_file.
import bpy
https://en.wikipedia.org/wiki/Batch_file
def write_some_data(context, filepath):
print("running write_some_data...")
f = open(filepath, 'w', encoding='utf-8')
f.write("@ECHO OFF\n")
f.write("ECHO Hello World!\n")
f.write(":: %s\n" % filepath)
f.write(":: %s\n" % bpy.data.filepath)
f.write("PAUSE")
f.close()
return {'FINISHED'}
ExportHelper is a helper class, defines filename and
invoke() function which calls the file selector.
from bpy_extras.io_utils import ExportHelper
from bpy.types import Operator
class ExportSomeData(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_test.some_data"
bl_label = "Export Some Data"
# ExportHelper mixin class uses this
filename_ext = ".bat"
filter_glob: bpy.props.StringProperty(default="*.bat", options={'HIDDEN'}, maxlen=255)
def execute(self, context):
return write_some_data(context, self.filepath)
def register():
bpy.utils.register_class(ExportSomeData)
def unregister():
bpy.utils.unregister_class(ExportSomeData)
if name == "main":
register()
bpy.ops.export_test.some_data('INVOKE_DEFAULT')
Output is:
@ECHO OFF
ECHO Hello World!
:: /Users/USER/Desktop/untitled.bat
:: /Users/USER/Desktop/untitled.blend
PAUSE