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?


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:
| improve this answer | |
  • $\begingroup$ Printing worked perfectly and showed the full file path. Thanks! $\endgroup$ – Keavon Jul 11 '15 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$ – Daniil Romanov Jul 11 '15 at 20:57
  • $\begingroup$ No problem, it was easy to google why it wasn't working and then fix it. $\endgroup$ – Keavon Jul 11 '15 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$ – scribblemaniac Jan 1 '16 at 1:33

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.