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()
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user