I've done a lot of searches but unless I'm missing something obvious (and I may be) I don't see any answers that don't involve already having a Blender file open (and I understand how to do that).

What I'd like to do is in my script be able to access the current directory that Blender opens up to load in Blender files. BEFORE any file is loaded. Because that default directory is where I want to store a config file to read parameters for my script (which can be run even if they don't have opened a Blender file).

Does that make sense? I can force a directory, of course, but I'd rather say to folks "just put the config in your default Blender directory" and then be able to find that file there.

All the answers seem to require first a file, like these:

bpy.path.abspath("//my\\file.txt")  # on Windows, with backslash escaped
bpy.path.abspath(r"//my\file.txt")  # on Windows, using python raw string
bpy.path.abspath("//../file.txt")  # to go back a directory

but I don't have a file. (And using the "//" alone gives me an error, although using two back slashes just gives me a single "\" as the result, which is NOT the current directory).

This seems stupidly simple but I'm feeling really dumb.


2 Answers 2

print(bpy.utils.resource_path('LOCAL'))   #Gives the default file locaton
print(bpy.utils.resource_path('USER'))    #Gives the blender installation location

You can use this as reference to go to other directories.


Shoot, here it is:

import os

But I looked for a couple of hours without luck. Sorry, folks.

  • 1
    $\begingroup$ Those are not the same. //some/path.txt means "relative to the currently open blendfile". os.getcwd() will give you the current working directory, which isn't related to which blendfile is open at all (on Windows it'll most likely give you 'C:\\Program Files\\Blender Foundation\\Blender'). $\endgroup$
    – dr. Sybren
    Commented Jun 3, 2018 at 9:17
  • $\begingroup$ Yeah, I found that out later, but at least it gives me a workable place to point folks to that won't change on their systems (unlike the relative to currently open blendfile). I guess there isn't just a "show default dir where I will open up Blender files" way, but that's acceptable right now. $\endgroup$ Commented Jun 4, 2018 at 10:09
  • 2
    $\begingroup$ That directory can't be written to by normal users, so it's rather pointless to send them there. Using os.path.expanduser('~') will give you the home directory of the user, which is much more likely to be what they want. $\endgroup$
    – dr. Sybren
    Commented Jun 4, 2018 at 10:28
  • 1
    $\begingroup$ Thanks, doc, that does seem to be better (I added a \\documents\\ to the path because that's a directory all should have there). This isn't so much for the world to use, so I wasn't too concerned about needing admin privileges, but it's definitely easier even for me not to have to invoke permissions each time. $\endgroup$ Commented Jun 5, 2018 at 17:01
  • $\begingroup$ If you want cross-platform support, you can't assume there is a documents folder there, nor can you use backslashes. Maybe that's relevant to you, maybe not ;-) $\endgroup$
    – dr. Sybren
    Commented Jun 5, 2018 at 17:13

You must log in to answer this question.

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