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']

I'm running 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 --python and --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)
    bpy.context.user_preferences.filepaths.script_directory = os.environ['BLENDER_ORIGINAL_SCRIPT_DIRECTORY']

#First launch (set script dir to pipeline and save, then launch a new Blender)
    #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']

    #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]

    cmd = subprocess.Popen(cmd_path, env=os.environ)

    #Close this version of Blender after the other has closed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.