5

How to get the value of this variable ?

enter image description here

jora
  • 53
  • 4
  • 1
    https://blender.stackexchange.com/questions/20850/how-to-automatically-get-a-add-on-folders-path-regardless-of-os pretty much module.__file__ ... eg import some_addon then print(some_addon.__file__} – batFINGER Mar 16 '21 at 21:34

2 Answers2

7

An add-on is just a regular python module so there are multiple ways to get the actual path.

You can use addon_utils, a module for addon management that comes with blender to filter the add-on and get the path:

import addon_utils
for mod in addon_utils.modules():
    print(mod.bl_info.get("name"))
    print(mod.__file__)

Or you can iterate through all enabled addons and use sys.modules dict:

import bpy
import sys

context = bpy.context

for mod_name in context.preferences.addons.keys(): mod = sys.modules[mod_name] print(mod.file)

Related: How can I get a list of the installed addons using the API?

brockmann
  • 12,613
  • 4
  • 50
  • 93
  • Do you happen to know how to get the path to the adonns, knowing only the N-panel ? image – jora Mar 16 '21 at 23:46
2

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

  • Hi, thanks for the post. This site is not a regular forum, answers should be substantial and thoroughly explain the solution and required workflow. One liners and code without context rarely make for a good answer. If you can [edit] your post and provide some more details about the procedure and why it works feel free to restore it, otherwise it may be deleted or converted into a comment. See How do I write a good answer? – Duarte Farrajota Ramos Nov 10 '21 at 21:52