I thought I’d share the final solution I ended up with.
Thanks to RobWuRob’s help, I have something much more flexible than using Environment Variables.
Everything is controlled thru a Python script instead, dynamically adding or removing script directories based on the script that was used. (Thanks RobWu)
I initially though that starting Addons in a Python Startup script didn’t work, but in fact it does. But there is a Bug in Blender, where preferences won’t show the proper state of the addons when doing so.
I’ve also noticed that Blender 4.2+ doesn’t use PYTHONPATH, so I first add a PATH to where my tools are. While also adding BQt to my pipeline and running it directly, instead of adding it to a Blender addon path.
The addon path are wiped clean initially, as the artist might have started another config previously. This way I can create launch configs for Modeling, Lighting or Animation, which just a few tweak of this .py script.
Finally, I can force enable addons that I want on with this config.
Blender is then launched using the config with:
blender --python lighting_config.py
I won’t be using Application Templates, as it wouldn’t be as flexible.
As artist will start any task using the pipeline, it can easily take care of starting up with a proper empty scene, with premade collections and whatnot depending on the task.
Here’s the code:
# Local imports
import bpy
import addon_utils
# Built-in imports
import sys
from pathlib import Path
# Setup Environment paths
launcher_path = Path.home() / ".env/repos/launcher/"
sys.path.append(str(launcher_path))
import launcher # Sets up enviroment
# Let's launch Pyside Integration
import blender_tools.bqt as bqt
print("Starting up BQt")
bqt.register()
# Let's add our custom addon paths
prefs = bpy.context.preferences
# Let's start by removing any sfs_ names ones, as these where created thru pipeline
for i, directory in enumerate(prefs.filepaths.script_directories):
if "sfs_" in directory.name:
bpy.ops.preferences.script_directory_remove(i)
# Let's add back the one specific to this template
dir_dict = {'sfs_general': "//fs01/env/packages/blender/base_tools/",
'sfs_lighting': "//fs01/env/packages/blender/light_tools/"}
for name, path in dir_dict.items():
bpy.ops.preferences.script_directory_add(directory=path, filter_folder=True)
# let's rename it
new_dir = bpy.context.preferences.filepaths.script_directories[-1]
new_dir.name = name
print(f"Added script directory: {path}")
# Insert any Addons that should be Loaded at launch
enabled_addons = ['node_wrangler']
for addon in enabled_addons:
addon_utils.enable(addon)