I did not found any way to update and run blender addon in blender without any moves inside blender. So, with this mode you can just press C-c C-a and your addon will be updated and reloaded automatically.
Pls, tell me if exist any bteter ways to do it :)
blend-mode.el:
(defvar addon-path nil
"path to root folder of your addon")
(defvar addon-name nil
"blender name of your addon")
(defvar blender-scene nil
"blender name of your addon")
(defvar blender-updater-script-path "~/.emacs.d/addon_updater.py"
"path to addon_update.py")
(defun touch-blender-file ()
(interactive)
(shell-command "touch /tmp/blender_reload"))
(defun run-blender ()
(interactive)
(if (not addon-name) (setq addon-name (read-string "Enter blender addon name:")))
(if (not addon-path) (setq addon-path (read-directory-name "Enter path to folder with __init__.py:")))
(if (not blender-scene) (setq blender-scene (read-file-name ".blend file path:")))
(start-process "blender process" "blender buffer"
"blender" blender-scene
"--python" (expand-file-name blender-updater-script-path)
"--" addon-name addon-path))
(define-minor-mode global-blender-mode
"Launch blender and feed it with addon."
:global t
:lighter "blender"
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-e") 'run-blender)
(define-key map (kbd "C-c C-a") 'touch-blender-file)
map)
(when global-blender-mode
(setq addon-name (file-name-nondirectory
(directory-file-name
(file-name-directory buffer-file-name))))
(setq addon-path (file-name-directory buffer-file-name))))
(provide 'global-blender-mode)
(global-set-key (kbd "C-c C-q") 'global-blender-mode)
addon-update.py:
#!/usr/bin/pyton
import bpy,sys,os,addon_utils
from bpy.app.handlers import persistent
import pipes
FILE_PATH = '/tmp/blender_reload'
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
addon_name = argv[0]
addon_path = argv[1]
addon_file_path = os.path.join(addon_path, "..", addon_name + ".zip")
@persistent
def update_handler(scene):
if os.path.isfile(FILE_PATH) :
os.remove(FILE_PATH)
os.chdir(addon_path)
os.chdir("..")
os.system("zip -r %s %s" % (addon_name + ".zip", addon_name))
bpy.ops.wm.addon_install(overwrite=True,
filepath=addon_file_path,
filter_folder=True,
filter_python=True,
filter_glob="*.zip")
addon_utils.enable(str(addon_name))
bpy.app.handlers.scene_update_pre.append(update_handler)