Environment Variable for Blender Addons

Exactly the same for me especially the part about not trusting settings transfer.

For me, it’s also about going back to old versions and having addons still work and having a centralized directory of addons just doesn’t let you do that. However, it’s a pain to have to copy addons to minor releases for portable versions so I have modified @sk_vfx’s script slightly since the last time I posted it so I never have to even change the environment variable name. My version of the script assumes there is a BLENDERXX_ADDONS_PATH(right now I’m on 36 for XX) environment variable that is pointed at the folder for that version. So when I setup a new major version, I just copy the script into the startup folder, create the environment variable and folder and then set my preferences again. Sometimes I can get away with copying the addons folder but usually major versions cause a lot of addon breakage and they have to be downloaded again anyway.

edit: Almost forgot: Minor versions are even easier, copy the config folder and the script into the startup folder and I’m ready to go.

edit2: Here’s the final version of my script for posterity:

import addon_utils
import bpy
from os import environ, pathsep
from os.path import normpath, isdir

ORIGINAL_PATHS_FUNC = addon_utils.paths

def register():
  def paths():
    addon_paths = ORIGINAL_PATHS_FUNC()
     
    blender_extra_scripts = environ.get(f'BLENDER{bpy.app.version[0]}{bpy.app.version[1]}_ADDON_PATHS')

    if blender_extra_scripts:
      blender_extra_scripts = blender_extra_scripts.split(pathsep)
      addon_paths += [normpath(_) for _ in blender_extra_scripts if isdir(_)]

    return addon_paths

  addon_utils.paths = paths

def unregister():
  addon_utils.paths = ORIGINAL_PATHS_FUNC

if __name__ == "__main__":
  register()
1 Like