Home | Trees | Indices | Help |
|
---|
|
This reference documents the Blender Python API, a growing collection of Python modules (libraries) that give access to part of the program's internal data and functions.
Through scripting Blender can be extended in real-time via Python, an impressive high level, multi-paradigm, open source language. Newcomers are recommended to start with the tutorial that comes with it.
This opens many interesting possibilities, ranging from automating repetitive tasks to adding new functionality to the program: procedural models, importers and exporters, even complex applications and so on. Blender itself comes with some scripts, but many others can be found in the Scripts & Plugins sections and forum posts at the Blender-related sites listed below.blender -P <scriptname>
will start Blender and execute the given script.
<scriptname> can be a filename in the user's file system or
the name of a text saved in a .blend Blender file: 'blender
myfile.blend -P textname'.
blender -b <blendfile> -P
<scriptname>
. <blendfile> can be any .blend
file, including the default .B.blend that is in Blender's home
directory Blender.Get('homedir'). In this mode no window
will be opened and the program will leave as soon as the script
finishes execution.
Python was embedded in Blender, so to access BPython modules you need to run scripts from the program itself: you can't import the Blender module into an external Python interpreter.
On the other hand, for many tasks it's possible to control Blender via some automated process using scripts. Interested readers should learn about features like "OnLoad" script links, the "-b <blendfile>" (background mode) and "-P <script>" (run script) command line options and API calls like Blender.Save, Blender.Load, Blender.Quit and the Library and Render modules.
Note that command line scripts are run before Blender initializes its windows (and in '-b' mode no window will be initialized), so many functions that get or set window related attributes (like most in Window) don't work here. If you need those, use an ONLOAD script link (see Scene.Scene.addScriptLink) instead -- it's also possible to use a command line script to write or set an ONLOAD script link. Check the Blender.mode module var to know if Blender is being executed in "background" or "interactive" mode.
Click here for command line and background mode examples.Programs manipulate data structures. Blender python scripts are no exception. Blender uses an Object Oriented architecture. The BPython interface tries to present Blender objects and their attributes in the same way you see them through the User Interface (the GUI). One key to BPython programming is understanding the information presented in Blender's OOPS window where Blender objects and their relationships are displayed.
Each Blender graphic element (Mesh, Lamp, Curve, etc.) is composed from two parts: an Object and ObData. The Object holds information about the position, rotation and size of the element. This is information that all elements have in common. The ObData holds information specific to that particular type of element.
Each Object has a link to its associated ObData. A single ObData may be shared by many Objects. A graphic element also has a link to a list of Materials. By default, this list is associated with the ObData.
All Blender objects have a unique name. However, the name is qualified by the type of the object. This means you can have a Lamp Object called Lamp.001 (OB:Lamp.001) and a Lamp ObData called Lamp.001 (LA:Lamp.001).
For a more in-depth look at Blender internals, and some understanding of why Blender works the way it does, see the Blender Architecture document.Author: The Blender Python Team
Requires: Blender 2.46 or newer.
Version: 2.46
Note: the official version of this reference guide is only updated for each new Blender release. But you can build the current SVN version yourself: install epydoc, grab all files in the source/blender/python/api2_2x/doc/ folder of Blender's SVN and use the epy_docgen.sh script also found there to generate the html docs. Naturally you will also need a recent Blender binary to try the new features. If you prefer not to compile it yourself, there is a testing builds forum at blender.org.
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Mon May 19 15:32:19 2008 | http://epydoc.sourceforge.net |