In Blender, is there a command to query what's the current path to the Add-on folder - regardless of what system I'm using?
3 Answers
$\begingroup$
$\endgroup$
4
Ah, got it.
Paste this to the Python Console to get your add-ons path:
bpy.utils.user_resource('SCRIPTS', "addons")
Also see the wiki.
-
2$\begingroup$ Note, there can be multiple addon's directories (3 infact) UsersHome/UserPrefs/BlenderDefault. The example you give will only give the user's home directory addon path, which might not even exist. $\endgroup$ Commented Dec 12, 2014 at 14:22
-
$\begingroup$ Oh, good to know. I guess they're listed here: blender.org/manual/installing_blender/directorylayout.html $\endgroup$ Commented Dec 12, 2014 at 14:24
-
1$\begingroup$ Both the links in this answer and in @ManuJärvinen comment are broken. $\endgroup$ Commented Apr 26 at 23:38
-
1$\begingroup$ @SandPiper Thanks, updated the link in the answer. (But the comment can't be edited) $\endgroup$ Commented May 2 at 8:00
$\begingroup$
$\endgroup$
If you want to know the directory of the currently-executing addon, try this:
import os
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
This is especially useful if your addon is a Python package, because it tells you which is the relevant subdirectory.
$\begingroup$
$\endgroup$
Blender addon utils module can fetch the path of any given addon name if installed.
#iterate through all the addon name installed
#if The Addon Name exists then:
#.__file__ will give away the file path where it is installed
#We are printing the file path in console
#If the given name does not exist it will pass
import bpy
import addon_utils
for mod in addon_utils.modules():
if mod.bl_info['name'] == "The Addon Name":
filepath = mod.__file__
print (filepath)
else:
pass