Abstract
CPython is a C-based implementation of Python. It even contains an API. This allows CPython to be used as an external library and linked with a separate application written in C. Functions defined by an “embedding” program may be called via Python script, running on the embedded interpreter. As such, Blender itself embeds a Python interpreter, providing access to some of its own functions. Python-callable functions must be registered using the Python API. This is done by Blender’s python module.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
At the time of this publication, Python 3.7 is the bundled version with Blender 2.83. The corresponding python.org documentation is https://docs.python.org/3.7/extending/embedding.html.
- 2.
You will see reference counting used in the methods added as part of Blender’s extended Python for Blender. The CPython API functions Py_INCREF() and Py_DECREF() are used for counting PyObject references.
- 3.
Incidentally, there is also a call to BaseMath_WriteCallback() in Vector_normalize(). Each PyObject subtype in mathutils may have a callback function. Callbacks are used by mathutils.Matrix (in MatrixObject) and implemented in functions with the suffix *_cb. The Vector_CreatePyObject_cb() allocation function, from mathutils_Vector.c, allocates a mathutils.Vector instance when the callback is invoked.
- 4.
Class methods of mathutils.Vector, i.e., ones that can be called without an instance of the mathutils.Vector class (known as static member functions in C++), have C_* prepended to their identifiers. Python class methods may update class state, but not object state.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2021 The Author(s), under exclusive license to APress Media, LLC , part of Springer Nature
About this chapter
Cite this chapter
Hollister, B.E. (2021). Blender’s Embedded Python. In: Core Blender Development. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-6415-7_5
Download citation
DOI: https://doi.org/10.1007/978-1-4842-6415-7_5
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-6414-0
Online ISBN: 978-1-4842-6415-7
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books