I'm trying to get Blender to launch with a custom script folder, is it possible without editing the preferences or files?
I'm in a company considering making a very slow phase out of Autodesk products, so I can't go editing program files, and I would prefer not writing to appdata.
The only way I've got automatically working is doing something like this (
blender.exe --python script.py), but it requires a reload before the paths work correctly, and I can only force it to quit.
if bpy.context.user_preferences.filepaths.script_directory != os.environ['BLENDER_PIPELINE_PATH']: bpy.context.user_preferences.filepaths.script_directory = os.environ['BLENDER_PIPELINE_PATH'] bpy.ops.wm.save_userpref() bpy.ops.wm.quit_blender()
sitecustomize.py to set bits up so I could potentially copy a master preferences file, but I don't really like the idea of doing that if there's a better alternative. Anyone have any tips?
Edit: I've kinda cheated a little. I launch the it with the
--background flags, save the prefs, then make a
subprocess call to a new Blender, which resets the prefs back to normal once it's loaded. Super messy but kinda gets around the issue for the time being, would still appreciate hearing a better solution.
#NOTE: This file also needs to be launched with Blender as a background process import os import sys import bpy #Second launch (set script dir back to original value) if 'BLENDER_ORIGINAL_SCRIPT_DIRECTORY' in os.environ: bpy.context.user_preferences.filepaths.script_directory = os.environ['BLENDER_ORIGINAL_SCRIPT_DIRECTORY'] bpy.ops.wm.save_userpref() #First launch (set script dir to pipeline and save, then launch a new Blender) else: #Set the pipeline path os.environ['BLENDER_ORIGINAL_SCRIPT_DIRECTORY'] = bpy.context.user_preferences.filepaths.script_directory bpy.context.user_preferences.filepaths.script_directory = os.environ['BLENDER_PIPELINE_PATH'] bpy.ops.wm.save_userpref() #Launch second process of Blender before this one is initialized import subprocess #Add this script to the path cmd_path = sys.executable for i, arg in enumerate(sys.argv): if arg == '--python': cmd_path += ' --python ' + sys.argv[i+1] break cmd = subprocess.Popen(cmd_path, env=os.environ) cmd.communicate() #Close this version of Blender after the other has closed bpy.ops.wm.quit_blender()