Setting script paths via python in startup script?

Hi,

Working from the application theme example in the blender documentation, I’m trying to set some variables for the preferences via scripting.
Most of it I got working just fine, but am a bit stumped with the new script folder code.

I have the following code that works:


import bpy
from bpy.app.handlers import persistent

@persistent
def load_handler_for_preferences(_):
    print("Changing Preference Defaults!")
    from bpy import context

    prefs = context.preferences

# Change Interface View settings
    prefs.use_preferences_save = False

# Change Data and Render File Paths
    paths = prefs.filepaths
    paths.temporary_directory = "S:\Temp"
    paths.render_cache_directory = "S:\Cache"

# Preferences - Save&Load - Blend Files
    paths.use_load_ui = False

# Change or Add Script Directory Paths
    scripts = prefs.something?
scripts.script_directory_add = 'W:/scripts/B_4.00/scripts'

I’m not entire sure how to set the script path variable, and set a name and path for any script directories I want to set this way. I looked at the documentation for directories but the add/remove and naming is all very vague.

cheers for any tips! :slight_smile:

You can create the directory with an operator, and specify the path.
Then you can reference it to change its name:

import bpy

script_path = 'W:/scripts/B_4.00/scripts'

# You can set the directory in the operator
bpy.ops.preferences.script_directory_add(directory=script_path)

# You can look it up by name or index after it's created
# It will be named after the last folder in the path
# In this case: 'scripts'
bpy.context.preferences.filepaths.script_directories['scripts'].name = 'Whatever You Want'
1 Like

Cheers man!
This works like a charm! :slight_smile: