4
$\begingroup$

I am having some problem in 'opening a file browser with python' in blender. Can you provide me with a sample code where I can access the file location after running from the script.

file browser.

Please, if you have full code it will help me better. I am very new to python.

$\endgroup$
1
  • 1
    $\begingroup$ You need to provide more context, is this part of an import operator, which invokes the file browser? Or a StringProperty(subtype='FILE_PATH') sitting in a panel? $\endgroup$
    – CodeManX
    Commented Jan 21, 2015 at 9:22

1 Answer 1

4
$\begingroup$

I found this code sample (originally from the Blender wiki) to be very helpful in understanding file browser usage. Specifically, look at the "execute" method of the ScanFileOperator class, which passes self.filepath (the chosen file) to another function (scanFile):

#
#   Opens a file select dialog and starts scanning the selected file.
#
class ScanFileOperator(bpy.types.Operator):
    bl_idname = "error.scan_file"
    bl_label = "Scan file for return"
    filepath = bpy.props.StringProperty(subtype="FILE_PATH")
 
    def execute(self, context):
        scanFile(self.filepath)
        return {'FINISHED'}
 
    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}
$\endgroup$
2
  • 1
    $\begingroup$ The link now doesn't exist. $\endgroup$
    – Hammerh5
    Commented Sep 15, 2020 at 16:38
  • $\begingroup$ @Hammerh5 Thanks for catching that, I updated the link. $\endgroup$
    – smashuu
    Commented Sep 16, 2020 at 15:17

You must log in to answer this question.

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