diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2008-10-20 16:33:31 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2008-10-20 16:33:31 +0400 |
commit | 47345cfd780a469bca4507d9b8d8f16dc56a2022 (patch) | |
tree | bfe7aeb3a9db7c879de13fd254d1fc24cb109c94 /source/blender/python | |
parent | 25859cf1f76d5c2363672bf17f5e328455d1f6af (diff) |
=== Blender Python API ===
After some discussion with Campbell, changed the way cstruct sizeof is fetched.
Moved DataSize() to Blender.Types.CSizeof(Blendertype). Supported types return sizeof(data struct), otherwise -1.
To quickly check what types are supported:
import Blender.Types as bt
x = dir(bt)
for t in x:
if t[0] != '_':
s = 'bt.CSizeof(bt.' + t + ')'
print t,"=", eval(s)
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/api2_2x/Armature.c | 24 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 9 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 31 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 12 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Types.c | 129 |
5 files changed, 126 insertions, 79 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index dab2d49df0c..aa3ef82a3e8 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -1295,27 +1295,6 @@ static PyObject *M_Armature_New(PyObject * self, PyObject * args) return (PyObject *)obj; } -static PyObject *M_Armature_DataSize(PyObject * self, PyObject *args) -{ - int t = 0; - int ret = 0; - if( !PyArg_ParseTuple(args, "|i", &t)) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected nothing or an int as argument" ); - - switch(t) { - case 0: - ret = sizeof(struct bArmature); - break; - default: - ret = sizeof(struct Bone); - break; - } - - return PyInt_FromLong(ret); -} - - //-------------------MODULE METHODS DEFINITION----------------------------- static char M_Armature_Get_doc[] = "(name) - return the armature with the name 'name', \ @@ -1324,12 +1303,9 @@ static char M_Armature_Get_doc[] = "(name) - return the armature with the name ' static char M_Armature_New_doc[] = "(name) - return a new armature object."; -static char M_Armature_DataSize_doc[] = "(type) - return sizeof of either Armature (0) or Bone (1)."; - struct PyMethodDef M_Armature_methods[] = { {"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc}, {"New", M_Armature_New, METH_VARARGS, M_Armature_New_doc}, - {"DataSize", M_Armature_DataSize, METH_VARARGS, M_Armature_DataSize_doc}, {NULL, NULL, 0, NULL} }; //------------------VISIBLE PROTOTYPE IMPLEMENTATION----------------------- diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 02fdc32c5c9..2e6bd326fb6 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -207,7 +207,6 @@ static PyObject *M_Material_New( PyObject * self, PyObject * args, PyObject * keywords ); static PyObject *M_Material_Get( PyObject * self, PyObject * args ); -static PyObject *M_Material_DataSize(PyObject *unused); /*****************************************************************************/ /* The following string definitions are used for documentation strings. In */ @@ -232,8 +231,6 @@ struct PyMethodDef M_Material_methods[] = { M_Material_New_doc}, {"Get", M_Material_Get, METH_VARARGS, M_Material_Get_doc}, {"get", M_Material_Get, METH_VARARGS, M_Material_Get_doc}, - {"DataSize", ( PyCFunction ) M_Material_DataSize, METH_NOARGS, - "Get sizeof() of Material"}, {NULL, NULL, 0, NULL} }; @@ -338,12 +335,6 @@ static PyObject *M_Material_Get( PyObject * self, PyObject * args ) } } -static PyObject *M_Material_DataSize(PyObject *unused) -{ - return PyInt_FromLong(sizeof(Material)); -} - - static PyObject *Material_ModesDict( void ) { PyObject *Modes = PyConstant_New( ); diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index fdecd66f5e2..d513a8be4db 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -8637,35 +8637,6 @@ static PyObject *M_Mesh_MVert( PyObject * self_unused, PyObject * args ) return PVert_CreatePyObject( &vert ); } -static PyObject *M_Mesh_DataSize(PyObject * self, PyObject *args) -{ - int t = 0; - int ret = 0; - if( !PyArg_ParseTuple(args, "|i", &t)) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected nothing or an int as argument" ); - - switch(t) { - case 0: - ret = sizeof(Mesh); - break; - case 1: - ret = sizeof(MVert); - break; - case 2: - ret = sizeof(MEdge); - break; - case 3: - ret = sizeof(MFace); - break; - default: - ret = sizeof(Mesh); - break; - } - - return PyInt_FromLong(ret); -} - static PyObject *M_Mesh_Modes( PyObject * self_unused, PyObject * args ) { int modes = 0; @@ -8697,8 +8668,6 @@ static struct PyMethodDef M_Mesh_methods[] = { "Create a new MVert"}, {"Mode", (PyCFunction)M_Mesh_Modes, METH_VARARGS, "Get/set edit selection mode(s)"}, - {"DataSize", (PyCFunction)M_Mesh_DataSize, METH_VARARGS, - "Get sizeof() of Mesh (0), MVert (1), MEdge (2) or MFace (3)"}, {NULL, NULL, 0, NULL}, }; diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index f14ac81fe24..1282b9bd82c 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -290,7 +290,6 @@ static PyObject *M_Object_New( PyObject * self, PyObject * args ); PyObject *M_Object_Get( PyObject * self, PyObject * args ); static PyObject *M_Object_GetSelected( PyObject * self ); static PyObject *M_Object_Duplicate( PyObject * self, PyObject * args, PyObject *kwd); -static PyObject *M_Object_DataSize( PyObject * self ); /* HELPER FUNCTION FOR PARENTING */ static PyObject *internal_makeParent(Object *parent, PyObject *py_child, int partype, int noninverse, int fast, int v1, int v2, int v3, char *bonename); @@ -319,9 +318,6 @@ The active object is the first in the list, if visible"; static char M_Object_Duplicate_doc[] = "(linked) - Duplicate all selected, visible objects in the current scene"; -static char M_Object_DataSize_doc[] = - "() - return the sizeof(Object)"; - /*****************************************************************************/ /* Python method structure definition for Blender.Object module: */ /*****************************************************************************/ @@ -334,8 +330,6 @@ struct PyMethodDef M_Object_methods[] = { M_Object_GetSelected_doc}, {"Duplicate", ( PyCFunction ) M_Object_Duplicate, METH_VARARGS | METH_KEYWORDS, M_Object_Duplicate_doc}, - {"DataSize", ( PyCFunction ) M_Object_DataSize, METH_NOARGS, - M_Object_DataSize_doc}, {NULL, NULL, 0, NULL} }; @@ -1042,12 +1036,6 @@ static PyObject *M_Object_Duplicate( PyObject * self_unused, Py_RETURN_NONE; } -static PyObject *M_Object_DataSize(PyObject * self) -{ - return PyInt_FromLong(sizeof(Object)); -} - - /*****************************************************************************/ /* Python BPy_Object methods: */ /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/Types.c b/source/blender/python/api2_2x/Types.c index 1ce19071885..10db016ab68 100644 --- a/source/blender/python/api2_2x/Types.c +++ b/source/blender/python/api2_2x/Types.c @@ -26,8 +26,10 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "Types.h" +#include "Types.h" #include "IDProp.h" +#include "gen_utils.h" +#include "BLI_blenlib.h" /* stuff pasted from the old Types.h is only need here now @@ -65,10 +67,130 @@ extern PyTypeObject ThemeSpace_Type; extern PyTypeObject ThemeUI_Type; extern PyTypeObject TimeLine_Type; +/* includes to get structs for CSizeof */ +#include "Armature.h" +#include "Bone.h" +#include "BezTriple.h" +#include "Camera.h" +#include "Constraint.h" +#include "Curve.h" +#include "CurNurb.h" +#include "Draw.h" +#include "Effect.h" +#include "Ipo.h" +#include "Ipocurve.h" +#include "Key.h" +#include "Lamp.h" +#include "Lattice.h" +#include "Library.h" +#include "Mathutils.h" +#include "Geometry.h" +#include "Mesh.h" +#include "Metaball.h" +#include "Modifier.h" +#include "NMesh.h" +#include "Node.h" +#include "Object.h" +#include "Group.h" +#include "Registry.h" +#include "Scene.h" +#include "Sound.h" +#include "SurfNurb.h" +#include "Sys.h" +#include "Text.h" +#include "Texture.h" +#include "Window.h" +#include "World.h" +#include "Particle.h" + char M_Types_doc[] = "The Blender Types module\n\n\ This module is a dictionary of all Blender Python types"; -struct PyMethodDef Null_methods[] = { {NULL, NULL, 0, NULL} }; +static PyObject *Types_CSizeof(PyObject * self, PyObject *o) +{ + int ret = 0; + char type[32]; + + if(o) { + sprintf(type, "%s", PyString_AsString(PyObject_Str(o))); + + if(BLI_streq(type, "<type 'Blender Action'>")==1) { + ret = sizeof(struct bAction); + } else if (BLI_streq(type, "<type 'Armature'>")==1) { + ret = sizeof(struct bArmature); + } else if (BLI_streq(type, "<type 'BezTriple'>")==1) { + ret = sizeof(struct BezTriple); + } else if (BLI_streq(type, "<type 'Bone'>")==1) { + ret = sizeof(struct Bone); + } else if (BLI_streq(type, "<type 'Blender Camera'>")==1) { + ret = sizeof(struct Camera); + } else if (BLI_streq(type, "<type 'CurNurb'>")==1) { + ret = sizeof(struct Nurb); + } else if (BLI_streq(type, "<type 'Curve'>")==1) { + ret = sizeof(struct Curve); + } else if (BLI_streq(type, "<type 'Blender Group'>")==1) { + ret = sizeof(struct Group); + } else if (BLI_streq(type, "<type 'Blender IDProperty'>")==1) { + ret = sizeof(struct IDProperty); + } else if (BLI_streq(type, "<type 'Blender Image'>")==1) { + ret = sizeof(struct Image); + } else if (BLI_streq(type, "<type 'Blender Ipo'>")==1) { + ret = sizeof(struct Ipo); + } else if (BLI_streq(type, "<type 'IpoCurve'>")==1) { + ret = sizeof(struct IpoCurve); + } else if (BLI_streq(type, "<type 'Blender Lamp'>")==1) { + ret = sizeof(struct Lamp); + } else if (BLI_streq(type, "<type 'Blender Lattice'>")==1) { + ret = sizeof(struct Lattice); + } else if (BLI_streq(type, "<type 'Blender MCol'>")==1) { + ret = sizeof(struct MCol); + } else if (BLI_streq(type, "<type 'Blender MEdge'>")==1) { + ret = sizeof(struct MEdge); + } else if (BLI_streq(type, "<type 'Blender MFace'>")==1) { + ret = sizeof(struct MFace); + } else if (BLI_streq(type, "<type 'Blender MTex'>")==1) { + ret = sizeof(struct MTex); + } else if (BLI_streq(type, "<type 'Blender MVert'>")==1) { + ret = sizeof(struct MVert); + } else if (BLI_streq(type, "<type 'Blender Material'>")==1) { + ret = sizeof(struct Material); + } else if (BLI_streq(type, "<type 'Blender Mesh'>")==1) { + ret = sizeof(struct Mesh); + } else if (BLI_streq(type, "<type 'Blender Metaball'>")==1) { + ret = sizeof(struct MetaBall); + } else if (BLI_streq(type, "<type 'Blender.Modifiers'>")==1) { + ret = sizeof(struct ModifierData); + } else if (BLI_streq(type, "<type 'Blender Modifier'>")==1) { + ret = sizeof(struct ModifierData); + } else if (BLI_streq(type, "<type 'Blender Object'>")==1) { + ret = sizeof(struct Object); + } else if (BLI_streq(type, "<type 'Pose'>")==1) { + ret = sizeof(struct bPose); + } else if (BLI_streq(type, "<type 'Blender RenderData'>")==1) { + ret = sizeof(struct RenderData); + } else if (BLI_streq(type, "<type 'Scene'>")==1) { + ret = sizeof(struct Scene); + } else if (BLI_streq(type, "<type 'SurfNurb'>")==1) { + ret = sizeof(struct Nurb); + } else if (BLI_streq(type, "<type 'Text3d'>")==1) { + ret = sizeof(struct Curve); + } else if (BLI_streq(type, "<type 'Blender Text'>")==1) { + ret = sizeof(struct Text); + } else if (BLI_streq(type, "<type 'Blender Texture'>")==1) { + ret = sizeof(struct Tex); + } else { + ret = -1; + } + } + + return PyInt_FromLong(ret); +} + +struct PyMethodDef M_Types_methods[] = { + {"CSizeof", Types_CSizeof, METH_O, + "(type) - Returns sizeof of the underlying C structure of the given type"}, + {NULL, NULL, 0, NULL} +}; @@ -145,7 +267,7 @@ PyObject *Types_Init( void ) PyObject *submodule, *dict; submodule = - Py_InitModule3( "Blender.Types", Null_methods, M_Types_doc ); + Py_InitModule3( "Blender.Types", M_Types_methods, M_Types_doc ); dict = PyModule_GetDict( submodule ); @@ -194,6 +316,7 @@ PyObject *Types_Init( void ) PyDict_SetItemString( dict, "CurveType", ( PyObject * ) &Curve_Type ); PyDict_SetItemString( dict, "IpoType", ( PyObject * ) &Ipo_Type ); + PyDict_SetItemString( dict, "IpoCurveType", ( PyObject * ) &IpoCurve_Type ); PyDict_SetItemString( dict, "MetaballType", ( PyObject * ) &Metaball_Type ); |