diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-03-06 15:37:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-03-06 15:37:29 +0300 |
commit | a53ef075aefb3626be583b561850537f5ba9cb8a (patch) | |
tree | d9d2664773beca09580108e374f6042c97eb7f5f /source/blender/python | |
parent | 1687a0b21eea478af3487c43ad26c2df0fe9f7ac (diff) |
python api function for rna objects: object.as_pointer()
This means we can write low level apis in pyton or C where blender data is passed to external C modules without having to have blender support this directly.
Example use case is to get an image pointer then use ctypes to get the image buffer and pass it to a C image processing function.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index d22297e3da9..5a114199005 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2347,6 +2347,14 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args) return def; } +static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self) +{ + if(self->ptr.data) + return PyCapsule_New(self->ptr.data, RNA_struct_identifier(self->ptr.type), NULL); + + Py_RETURN_NONE; +} + static PyObject *pyrna_prop_get(BPy_PropertyRNA *self, PyObject *args) { PointerRNA newptr; @@ -2661,6 +2669,8 @@ static struct PyMethodDef pyrna_struct_methods[] = { {"get", (PyCFunction)pyrna_struct_get, METH_VARARGS, NULL}, + {"as_pointer", (PyCFunction)pyrna_struct_as_pointer, METH_NOARGS, NULL}, + /* maybe this become and ID function */ {"keyframe_insert", (PyCFunction)pyrna_struct_keyframe_insert, METH_VARARGS, NULL}, {"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL}, |