Graphics Reference
In-Depth Information
bpy.data Provides access to datablocks in the current blend file, independent of the context. For example,
information about bones independent of posing (such as the information you would access in Edit mode) is
accessible through bpy.data .
bpy.ops Providesaccesstooperators.TheseenablePythonscriptstocarryoutthesamekindsofoperations
that you would carry out as a user of Blender. There are operators available for every possible context and
window type.
bpy.types Provides access to miscellaneous useful classes that are not represented as datablocks in
Blender. These include window and interface elements.
bpy.utils Provides access to Blender utilities that don't deal with Blender internal data. Many of these
utilities deal with managing external data paths.
bpy.path Provides access to utilities for parsing and processing the paths themselves.
bpy.app Provides access to application data that remains unchanged during runtime. Debug settings, C
compiler flags, the location of the Blender executable on your computer, and similar information are access-
ible through bpy.app .
bpy.props Provides access to the properties system. This makes it possible to extend Blender's internal
data using properties. The properties system has built-in tools for creating graphical user interface access to
property values.
The application modules and the most commonly used stand-alone modules are imported automatically in
the Blender Python interactive command-line console. Other stand-alone modules can be imported in the in-
teractive console using the import command. The BGE modules are not available for import in the interact-
ive console environment, further underscoring the distinction between how those modules are used. In Blender
Python scripts, modules must be imported using the import command, as you'll see throughout this chapter.
ThecompleteAPIspecifications(all1,397pagesasofthiswriting)areavailableinPDFformatfordownload
as well as online at www.blender.org/documentation/blender_python_api_2_62_3 .
Calling Functions from the Command Line
Blender's interactive console is a great tool for quickly checking on API information. To work with this, open a
Python Console in your Blender work area. Be sure to keep your 3D viewport open also.
Exploring with the Autocomplete Function
The autocomplete function (Ctrl+spacebar) is a handy way to look up methods available to a given module or
object. For example, to explore the operators available in bpy.ops , type bpy.ops. into the command line
like this
>>> bpy.ops.
followed by Ctrl+spacebar to activate autocompletion. You'll see a list of possible continuations, represent-
ing classes of operators.
Let's say you wanted to add a mesh primitive to the scene. Adding mesh primitives to a scene is one of the
low-level operators available to bpy.ops , so you can do this with one line of code. (If you want to add more
complex mesh objects, you'll need to code the operator by hand, as you will see later in this chapter.)
Search WWH ::




Custom Search