I want to write an add-on that can open a file opened with Blender (i.e. double clicked while Blender is the default program associated with the file format). That means Blender is opened with launch arguments holding the path to the opened file. This must work for file formats other than .blend, such as .fbx. In the Python code for an add-on, how can I access the path of the file opened with Blender. Or the arguments Blender launched with?


1 Answer 1


bpy.context.blend_data.filepath - full path and name of opened .blend file. I doubt there is something for imported files, because they are "adding" to scene, not "opening"

For other arguments you can use standard recipe:

import sys
for arg in sys.argv:
  • $\begingroup$ Printing worked perfectly and showed the full file path. Thanks! $\endgroup$
    – Keavon
    Commented Jul 11, 2015 at 20:35
  • $\begingroup$ Glad to help you. That was a little strange, that I wrote here code for Python 2 when I switched to Python 3 some years ago, and just checked correct code in my Blender. $\endgroup$ Commented Jul 11, 2015 at 20:57
  • $\begingroup$ No problem, it was easy to google why it wasn't working and then fix it. $\endgroup$
    – Keavon
    Commented Jul 11, 2015 at 21:08
  • $\begingroup$ Alternatively, for getting the path of the opened .blend file you can use bpy.data.filepath which gets you the exact same file path as the above method. $\endgroup$ Commented Jan 1, 2016 at 1:33

You must log in to answer this question.

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