3
$\begingroup$

Is it possible to install a Blender addon in headless mode? I need the ability to export gltfs from a Ubuntu server instance and the only instructions I can find for installing an addon in Blender is through the GUI.

Is there a command line argument? Or is it possible to unzip the addon somewhere that will work with Blender?

$\endgroup$
  • $\begingroup$ You should be able to install by unzipping into Blender\2.##\scripts\addons, though you still need to activate it to be able to use it. $\endgroup$ – Duarte Farrajota Ramos Feb 16 '17 at 4:44
3
$\begingroup$

You can just unzip the add-on into the /2.7x/scripts/addons/ directory. On Linux, it should be in the same directory as Blender. If there is more than just a single Python script, make sure to put the whole unzipped folder in, not just its contents.

To enable the add-on, you'll need to swap out the user preferences .blend file, found at /2.7x/config/userpref.blend. On a computer with a GUI, install and enable the add-on, and any other add-ons you want to use. Save the user preferences, and then copy the userpref.blend file to the appropriate spot on the Linux server.

$\endgroup$
9
$\begingroup$

Using python you can install an addon with bpy.ops.wm.addon_install(), you can then enable the addon with bpy.ops.wm.addon_enable() and disable it with bpy.ops.wm.addon_disable(). To keep the addon enabled every time you start blender you save your settings with bpy.ops.wm.save_userpref()

For addon_install you give it the filepath to the addon, this is the same file you would choose if you were using blender's GUI.

To enable or disable an addon you need to specify the module name, that is the folder name installed into the addons folder or the filename without .py for single file addons.

import bpy
bpy.ops.wm.addon_install(filepath='/home/shane/Downloads/testaddon.py')
bpy.ops.wm.addon_enable(module='testaddon')
bpy.ops.wm.save_userpref()

There are two ways you can make this work remotely through the CLI.

Save the steps in a script and run it.

blender -b -P enableaddon.py

Start blender as a python console and type each in directly.

blender -b --python-console
Python 3.5.2 <snip...>
(InteractiveConsole)
>>> import bpy
>>> bpy.ops.wm.addon_install(filepath='/home/shane/Downloads/testaddon.py')
>>> bpy.ops.wm.addon_enable(module='testaddon')
>>> bpy.ops.wm.save_userpref()

Use ⎈ CtrlD to exit the python console and quit blender.

$\endgroup$
  • $\begingroup$ I compiled blender as a python module and I got the install to work with your script - however the settings will be gone whenever I reload the script. Any clues on how to change this? $\endgroup$ – davidwessman Feb 23 '18 at 9:11
  • $\begingroup$ I'm not sure if bpy as a module will read a startup.blend. Check the preference locations to see if one gets saved into place. Worst case is to use a script to adjust settings before doing the task you want. $\endgroup$ – sambler Feb 23 '18 at 12:04
  • $\begingroup$ @sambler I have compiled Blender as a Python3 module so I don't have access to the GUI. I am installing an addon and enable it using the bpy module. I then save the user preferences using bpy.ops.wm.save_userpref() and exit Python. Next time that I do import bpy I don't see the addon API being added to the bpy module.Do you know how I can fix that?If I run the same exact script in Blender terminal (when using the GUI) everything works fine.(You may answer here) $\endgroup$ – Amir Sep 17 '18 at 19:57
0
$\begingroup$

Try the overwrite=True option, as shown below. Also please note that for directories, you will need to pass the zipped file:

bpy.ops.wm.addon_install(overwrite=True, filepath="module_dir.zip")

Also when using CLI, you may need to pass -y option to enable automatic Python script execution

blender -b  -y  --python ebableaddon.py  my_blend_file.blend -o output_file -a
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.