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?
$\begingroup$
$\endgroup$
2
-
$\begingroup$ you should try my addon. in one operation you can select all addons in a folder. confirm. it's done. this is checking if it's an update if you let the default option in the browser. you can also install an addon directly from the text editor github.com/1C0D/Addon_Installer-Script_Runner-BlenderAddon $\endgroup$– Uneconscience UneSourceCommented Oct 7, 2020 at 15:16
-
$\begingroup$ I use it intensively when I'm doing addons $\endgroup$– Uneconscience UneSourceCommented Oct 7, 2020 at 15:17
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
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)