Blender Python Mode - Blender Python development with Emacs
The Blender Python Mode makes it easy to use Emacs for Blender Python development. It is based on the Command Port branch of Blender and on Dave Love's python.el mode included in Emacs 22.
The Blender Python Mode is still experimental and in the process of development - so please don't wonder if not everything works as it should :)
Screenshot
Console, Blender Server, emacs client and shell client
Links
- Blender home page
- Blender Command Port page
- Blender Python Mode sources on Launchpad
- PythonMode page on the EmacsWiki and python.el on Dave Love's "Emacs bits" page
Example - a simple pyramid
- Download and install the Blender Python Mode
-
Start emacs with the following command
emacs \ --no-init-file --no-site-file --no-splash \ --debug-init \ --eval " (progn (define-key global-map \"\\C-h\" (quote delete-backward-char)) ;; mapping Control-h to delete-backward-char (defvar blender-python-mode-installation-dir \"$BPM/blender-python-mode\") (setq load-path (add-to-list 'load-path blender-python-mode-installation-dir)) (require 'blender-python-mode) (find-file (concat blender-python-mode-installation-dir \"/python-example-file.py\"))) "
where $BPM is the directory where you installed the Blender Python Mode sources. -
Emacs should start and display the file
blender-python-mode/python-example-file.py
as found in the Blender Python Mode source distribution:
# -*- mode: blender-python -*- # a one-line command print 'Hello %s :)' % 'Blender Python Mode' # region-begin - a little script to generate a simple pyramid from Blender import * vertexes = [[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0], [0, 0, 1.27]] faces = [[3, 2, 1, 0], [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4]] mesh = Mesh.New('mesh') mesh.verts.extend(vertexes) mesh.faces.extend(faces) scene = Scene.GetCurrent() object = scene.objects.new(mesh, 'object') Redraw() # region-end
-
Start the Blender server and the emacs blash client with
Emacs Menu: Blender -> Start
or one by one withEmacs Menu: Blender -> Start Blender Server
and afterEmacs Menu: Blender -> Start Blash
-
If you now move the Emacs point to line
print 'Hello %s :)' % 'Blender Python Mode'
and hit C-return the *Blash* buffer should pop up and the string "Hello Blender Python Mode :)" should be printed. -
If you evaluate the following code from file
python-example-file.py
line by line in the same way
a little pyramid should be displayed in the blender 3D view:
from Blender import * vertexes = [[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0], [0, 0, 1.27]] faces = [[3, 2, 1, 0], [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4]] mesh = Mesh.New('mesh') mesh.verts.extend(vertexes) mesh.faces.extend(faces) scene = Scene.GetCurrent() object = scene.objects.new(mesh, 'object') Redraw()
If you want to execute more than one line at once, different emacs commands can be used:
- You can mark a region in the emacs buffer and use the emacs menu Blender -> Execute region (Shortcut: C-xC-r) to execute the region;
- You also can move the point into a region delimited by the comment lines # region-begin and # region-end and use Blender -> Execute region between `region-begin' and `region-end' (Shortcut: C-xC-e) to execute all lines between region-begin and region-end at once.
Installation
- The Blender Python Mode relies on the Blender Command Port branch of Blender. So you first have to install the Command Port Blender as described on the page "Command Port Blender - Installation".
- You also have to ensure that Dave Love's python mode is installed. When using Emacs 22 you might consider to reinstall python mode from python.el as the version included in Emacs 22 seems to have some problems which are fixed in the version mentioned above. When using Emacs 21 you should install python-21.el. For more information see the PythonMode page on the EmacsWiki and Dave Love's "Emacs bits" page.
-
Make a directory for the blender python mode sources
BPM=$HOME/blender/emacs mkdir -p $BPM cd $BPM
-
Download the sources from the
Blender Python Mode code page
at
launchpad.
bzr branch lp:~diresu/blender-python-mode/blender-python-mode
- Test your installation as described in paragraph "example - a simple pyramid".
Customization
-
You can customize emacs to load the Blender Python Mode when starting up
by adding the following lines to your .emacs file:
(defvar blender-python-mode-installation-dir "$BPM/blender-python-mode") (setq load-path (add-to-list 'load-path blender-python-mode-installation-dir)) (require 'blender-python-mode)
Please substitute the token $BPM with the directory where you installed the Blender Python Mode sources. -
Other customization options are available from
Emacs Menu: Blender -> Customization