diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-21 02:39:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-21 02:39:29 +0300 |
commit | c30149991c9417106577e2d96112b16433910215 (patch) | |
tree | 9b686c141ddf2c9346ebe0beb3b3cfc3aaacf73f /source/blender/python/intern/bpy.c | |
parent | 55a0e21a03e88e5489dd6f53a91b6f3a6f770d9a (diff) |
Experimental option to build blender as a python module, rather then blender embedding python.
CMake build option WITH_PYTHON_MODULE, will build ./bin/bpy.so
This allows 'bpy' to be imported from python or other applications/IDE's which embed python, eg:
python -c "import bpy ; bpy.ops.render.render(write_still=True)"
This runs in background mode and has similar restrictions to running a script:
blender --background --python test.py
TODO:
- install to site-packages with blender scripts
- add support for imp.reload()
Diffstat (limited to 'source/blender/python/intern/bpy.c')
-rw-r--r-- | source/blender/python/intern/bpy.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 8076515b94b..02073f368e8 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -53,6 +53,8 @@ #include "AUD_PyInit.h" +PyObject *bpy_package_py= NULL; + static char bpy_script_paths_doc[] = ".. function:: script_paths()\n" "\n" @@ -161,7 +163,7 @@ static PyMethodDef meth_bpy_script_paths = {"script_paths", (PyCFunction)bpy_scr static PyMethodDef meth_bpy_blend_paths = {"blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc}; static PyMethodDef meth_bpy_user_resource = {"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, NULL}; -static void bpy_import_test(const char *modname) +static PyObject *bpy_import_test(const char *modname) { PyObject *mod= PyImport_ImportModuleLevel((char *)modname, NULL, NULL, NULL, 0); if(mod) { @@ -170,7 +172,9 @@ static void bpy_import_test(const char *modname) else { PyErr_Print(); PyErr_Clear(); - } + } + + return mod; } /***************************************************************************** @@ -235,5 +239,5 @@ void BPy_init_modules( void ) PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL)); /* add our own modules dir, this is a python package */ - bpy_import_test("bpy"); + bpy_package_py= bpy_import_test("bpy"); } |