Last active
June 24, 2020 15:37
-
-
Save melsov/f0621fd01fc8d5b52e8d0628ec177fdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to run a Blender add-on from the command line. | |
WHY: its easier than re-zipping, and restarting blender everytime you want to | |
test a change to an add-on you're developing | |
In short: run blender from the command line and | |
use an option to get it to run a python script | |
that registers and invokes your add-on. | |
Here's the command that will do it in the end (explanation below): | |
blender E:\assets\arrow.blend --python-use-system-env --python run-addon.py | |
Explanation / Steps: | |
--add blender exec to your system path (for convenience) | |
--make a new directory somehere. say: "E:\blender\dev" | |
--add this directory to your PYTHONPATH environment variable | |
(for importing a module that you'll put inside the directory you just made) | |
--probably need to: disable the existing version of the add-on you want to work on in blender. | |
--copy the source folder for the add-on into your 'E:\blender\dev' dir. | |
(where source folder means the one containing the top level __init__.py) | |
--optional: rename the copied add-on directory/module. e.g. 'babylon_js' -> 'babylon_dev_js' | |
--make a new python script file in the 'blender\dev' directory. Call it "run-addon.py" (or whatever you want). | |
--if your add-on is named 'babylon_dev_js' | |
run-addon.py should look like this: | |
#### RUN-ADDON.PY ##### | |
import babylon_dev_js | |
import bpy | |
print('hi from run-addon.py') | |
babylon_dev_js.register() | |
# try bab exporter | |
print('trying the bab exporter') | |
# invoke the add-on (call its execute() method) | |
bpy.ops.export.bjs() | |
# quit blender for convenience, if you want | |
bpy.ops.wm.quit_blender() | |
#### END OF RUN-ADDON.PY #### | |
Now you can run: | |
blender E:\assets\arrow.blend --python-use-system-env --python run-addon.py | |
to test the add-on. ('arrow.blend' is the file you want to | |
open in blender. Leave out to run on the default scene.) | |
SOME NOTES: | |
In my case, I had to help the addon to work without user interaction. | |
E.g. set a value for self.filepath in the execute() method before it did anything | |
that relied on having a value there: | |
self.filepath = "E:\some\path\arrow.babylon" | |
Since my dev copy of the add-on has a different name from the stable version | |
I can check the add-ons name before performing this set up step. useful (i guess) if I ever want to | |
actually use a non dev version and don't want to have to remember to undo the dev only stuff: | |
if __name__ == 'babylon_dev_js': | |
self.filepath = "E:\some\useful\path\arrow.babylon' | |
ALTERNATE METHOD: | |
install the add-on in blender in the usual way | |
and simply edit the copy in blender's add-on folder. | |
BETTER because: fewer steps. no need to edit your PYTHONPATH. | |
WORSE because: seems messier. maybe you actually want to use the stable version of the add-on. | |
If you make a dev copy of the module, you can change its name (i.e. change the folder name). | |
You can then check against the __name__ variable in the module's code to see if you're | |
running the dev version or not. | |
ALTERNATE STEPS: | |
--Install the add-on | |
--Add blender to your PATH | |
--now run-addon.py looks like: | |
#### RUN-ADDON.PY ##### | |
import bpy | |
print('hi from run-addon.py') | |
# try bab exporter | |
print('trying the bab exporter') | |
# invoke the add-on (call its execute() method) | |
bpy.ops.export.bjs() | |
# quit blender for convenience, if you want | |
bpy.ops.wm.quit_blender() | |
#### END OF RUN-ADDON.PY #### | |
--and I think you can omit the --python-use-system-env flag in the command since you don't | |
need to import the add-on module | |
blender E:\assets\arrow.blend --python run-addon.py | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment