look at string subtypes especially. From what i gather so quickly, youâll need to add another stringproperty with a subtype set to âFILE_NAMEâ. Assuming that this call:
context.window_manager.fileselect_add(self)
invokes the actual file browser and that it populates those string properties for you. I canât find a way to open it while specifying a directory to look at, i think it defaults to the last known directory. You could try adding a âDIR_PATHâ stringproperty and hope for the best though. Note that this code example is from the âOperatorsâ page I also linked.
import bpy
class ExportSomeData(bpy.types.Operator):
"""Test exporter which just writes hello world"""
bl_idname = "export.some_data"
bl_label = "Export Some Data"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
file = open(self.filepath, 'w')
file.write("Hello World " + context.object.name)
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
# Only needed if you want to add into a dynamic menu
def menu_func(self, context):
self.layout.operator_context = 'INVOKE_DEFAULT'
self.layout.operator(ExportSomeData.bl_idname, text="Text Export Operator")
# Register and add to the file selector
bpy.utils.register_class(ExportSomeData)
bpy.types.TOPBAR_MT_file_export.append(menu_func)
# test call
bpy.ops.export.some_data('INVOKE_DEFAULT')
An alternative if you canât get it to work would be to just populate a pulldown menu/previewscollection with files from the selected directory. This is done with enumproperties, item callback and update functions.