7
$\begingroup$

I am constantly using new workstations where I have to install a new version of blender. While the blender cloud add-on allows one to sync settings between devices, it does not sync user-installed add-ons themselves. If I have all the add-ons I want to install in a folder I download form a cloud location, how could I create a script that would automatically install and activate them?

$\endgroup$
2

1 Answer 1

7
$\begingroup$

You can designate the folder with the scripts, create a list of files within this folder (i.e., directory), and use the preferences.addon_install() command on each file. You can create a list of the module names you want to install, and then loop through them with preferences.addon_enable()

import os
import bpy


# Define path to your downloaded script
path_to_script_dir = os.path('/Users/YourUserName/Downloads/scripts')

#Define a list of the files in this folder, i.e. directory. The method listdir() will return this list from our folder of downloaded scripts. 
file_list = sorted(os.listdir(path_to_script_dir))

#Further specificy that of this list of files, you only want the ones with the .zip extension.
script_list = [item for item in file_list if item.endswith('.zip')]
 
#Specify the file path of the individual scripts (their names joined with the location of your downloaded scripts folder) then use wm.addon_install() to install them. 
for file in file_list:
    path_to_file = os.path.join(path_to_script_dir, file)
    bpy.ops.preferences.addon_install(overwrite=True, target='DEFAULT', filepath=path_to_file, filter_folder=True, filter_python=False, filter_glob="*.py;*.zip")

#Specify which add-ons you want enabled. For example, Crowd Render, Pie Menu Editor, etc. Use the script's python module. 
enableTheseAddons = ['crowdrender', 'pie_menu_editor', 'animation_nodes','blender_cloud']

#Use addon_enable() to enable them.
for string in enableTheseAddons: 
    name = enableTheseAddons
    bpy.ops.preferences.addon_enable(module = string)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .