Module Blender
[frames | no frames]

Module Blender

The main Blender module.

New: Run, UpdateMenus, new options to Get, ShowHelp, SpaceHandlers dictionary.

Blender


Function Summary
  Get(request)
Retrieve settings from Blender.
  Load(filename)
Load a Blender .blend file or any of the other supported file formats.
  Quit()
Exit from Blender immediately.
  Redraw()
Redraw all 3D windows.
  Run(script)
Execute the given script.
  Save(filename, overwrite)
Save a Blender .blend file with the current program data or export to one of the builtin file formats.
  Set(request, data)
Update settings in Blender.
  ShowHelp(script)
Show help for the given script.
  UpdateMenus()
Update the menus that list registered scripts.

Variable Summary
bool bylink: True if the current script is being executed as a script link.
string or int event: this has three possible uses: script link type or events callback ascii value:
Blender Object or None; integer (space handlers) link: for normal script links, 'link' points to the linked Object (can be a scene, object (mesh, camera, lamp), material or world).
string mode: Blender's current mode:
constant dictionary SpaceHandlers: dictionary with space handler types.

Function Details

Get(request)

Retrieve settings from Blender.
Parameters:
request - The setting data to be returned:
  • 'curframe': the current animation frame.
  • 'curtime' : the current animation time.
  • 'staframe': the start frame of the animation.
  • 'endframe': the end frame of the animation.
  • 'filename': the name of the last file read or written.
  • 'homedir': Blender's home dir.
  • 'datadir' : the path to the dir where scripts should store and retrieve their data files, including saved configuration (can be None, if not found).
  • 'udatadir': the path to the user defined data dir. This may not be available (is None if not found), but users that define uscriptsdir have a place for their own scripts and script data that won't be erased when a new version of Blender is installed. For this reason we recommend scripts check this dir first and use it, if available.
  • 'scriptsdir': the path to the main dir where scripts are stored.
  • 'uscriptsdir': the path to the user defined dir for scripts. (*)
  • 'yfexportdir': the path to the user defined dir for yafray export. (*)
  • 'fontsdir': the path to the user defined dir for fonts. (*)
  • 'texturesdir': the path to the user defined dir for textures. (*)
  • 'texpluginsdir': the path to the user defined dir for texture plugins. (*)
  • 'seqpluginsdir': the path to the user defined dir for sequence plugins. (*)
  • 'renderdir': the path to the user defined dir for render output. (*)
  • 'soundsdir': the path to the user defined dir for sound files. (*)
  • 'tempdir': the path to the user defined dir for storage of Blender temporary files. (*)
  • 'version' : the Blender version number.

           (type=string)
Returns:
The requested data or None if not found.

Warning: this function returns None for requested dir paths that have not been set or do not exist in the user's file system.

Note: (*) these can be set in Blender at the User Preferences window -> File Paths tab.

Load(filename=None)

Load a Blender .blend file or any of the other supported file formats.

Supported formats:
  • Blender's .blend;
  • DXF;
  • Open Inventor 1.0 ASCII;
  • Radiogour;
  • STL;
  • Videoscape;
  • VRML 1.0 asc.
Parameters:
filename - the pathname to the desired file. If 'filename' isn't given or if it contains the substring '.B.blend', the default .B.blend file is loaded.
           (type=string)

Warnings:

  • loading a new .blend file removes the current data in Blender. For safety, this function saves the current data as an autosave file in the temporary dir used by Blender before loading a new Blender file.
  • after a call to Load(blendfile), current data in Blender is lost, including the Python dictionaries. Any posterior references in the script to previously defined data will generate a NameError. So it's better to put Blender.Load as the last executed command in the script, when this function is used to open .blend files.
  • if in edit mode, this function leaves it, since Blender itself requires that.

Quit()

Exit from Blender immediately.

Warning: the use of this function should obviously be avoided, it is available because there are some cases where it can be useful, like in automated tests. For safety, a "quit.blend" file is saved (normal Blender behavior upon exiting) when this function is called, so the data in Blender isn't lost.

Redraw()

Redraw all 3D windows.

Run(script)

Execute the given script.
Parameters:
script - the name of an available Blender Text (use Text.Get() to get a complete list) or the full pathname to a Python script file in the system.
           (type=string)

Note: the script is executed in its own context -- with its own global dictionary -- as if it had been executed from the Text Editor or chosen from a menu.

Save(filename, overwrite=0)

Save a Blender .blend file with the current program data or export to one of the builtin file formats.

Supported formats:
  • Blender (.blend);
  • DXF (.dxf);
  • STL (.stl);
  • Videoscape (.obj);
  • VRML 1.0 (.wrl).
Parameters:
filename - the filename for the file to be written. It must have one of the supported extensions or an error will be returned.
           (type=string)
overwrite - if non-zero, file 'filename' will be overwritten if it already exists (can be checked with Blender.sys.exists. By default existing files are not overwritten (an error is returned).
           (type=int (bool))

Notes:

  • The substring ".B.blend" is not accepted inside 'filename'.
  • DXF, STL and Videoscape export only selected meshes.

Set(request, data)

Update settings in Blender.
Parameters:
request - The setting to change:
  • 'curframe': the current animation frame

           (type=string)
data - The new value.
           (type=int)

ShowHelp(script)

Show help for the given script. This is a time-saver ("code-saver") for scripts that need to feature a 'help' button in their GUI's or a 'help' submenu option. With proper documentation strings, calling this function is enough to present a screen with help information plus link and email buttons.
Parameters:
script - the filename of a registered Python script.
           (type=string)

Notes:

  • this function uses Run and the "Scripts Help Browser" script. This means that it expects proper doc strings in the script to be able to show help for it (otherwise it offers to load the script source code as text). The necessary information about doc strings is in the Intro page of this API Reference documentation you're reading.
  • 'script' doesn't need to be a full path name: "filename.py" is enough. Note, though, that this function only works for properly registered scripts (those that appear in menus).

UpdateMenus()

Update the menus that list registered scripts. This will scan the default and user defined (if available) folder(s) for scripts that have registration data and will make them accessible via menus.

Note: only scripts that save other new scripts in the default or user defined folders need to call this function.


Variable Details

bylink

True if the current script is being executed as a script link.
Type:
bool

event

this has three possible uses: script link type or events callback ascii value:
  • for normal script links it is a string representing the link type (OnLoad, FrameChanged, Redraw, etc.).
  • for EVENT space handler script links it is the passed event.
  • for normal GUI scripts during the events callback, it holds the ascii value of the current event, if it is a valid one. Users interested in this should also check the builtin 'ord' and 'chr' Python functions.
Type:
string or int

link

for normal script links, 'link' points to the linked Object (can be a scene, object (mesh, camera, lamp), material or world). For space handler script links, 'link' is an integer from the Blender.SpaceHandlers dictionary. For script not running as script links, 'link' is None.
Type:
Blender Object or None; integer (space handlers)

mode

Blender's current mode:
  • 'interactive': normal mode, with an open window answering to user input;
  • 'background': Blender was started as 'blender -b <blender file>' and will exit as soon as it finishes rendering or executing a script (ex: 'blender -b <blender file> -P <script>'). Try 'blender -h' for more detailed informations.
Type:
string

SpaceHandlers

dictionary with space handler types.
  • VIEW3D_EVENT;
  • VIEW3D_DRAW.
Type:
constant dictionary

Generated by Epydoc 2.1 on Mon Jun 13 15:31:22 2005 http://epydoc.sf.net