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.

  • 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 Jan 21 '15 at 9:22

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):
        return {'FINISHED'}
    def invoke(self, context, event):
        return {'RUNNING_MODAL'}
| improve this answer | |
  • $\begingroup$ The link now doesn't exist. $\endgroup$ – Hammerh5 Sep 15 at 16:38
  • $\begingroup$ @Hammerh5 Thanks for catching that, I updated the link. $\endgroup$ – smashuu Sep 16 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.