From cfa48583ae1dd32a8d1575447c659c9786b0f406 Mon Sep 17 00:00:00 2001 From: Jacques Guignot Date: Sun, 26 Oct 2003 16:54:33 +0000 Subject: added a new function : getCurve(string) allowing access to an ipo curve from its name. --- source/blender/python/api2_2x/Ipo.c | 104 ++++++++++++++++++++++++++++++------ source/blender/python/api2_2x/Ipo.h | 3 ++ 2 files changed, 91 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c index 1c506199324..f243cfb9b23 100644 --- a/source/blender/python/api2_2x/Ipo.c +++ b/source/blender/python/api2_2x/Ipo.c @@ -53,7 +53,7 @@ static PyObject *M_Ipo_New(PyObject *self, PyObject *args) if (!strcmp(code,"Material"))idcode = ID_MA; if (idcode == -1) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad code")); - + printf("%d %d %d \n", ID_OB, ID_CA, ID_WO); blipo = add_ipo(name,idcode); if (blipo) @@ -264,27 +264,89 @@ static PyObject *Ipo_getNcurves(C_Ipo *self) } +int num_from_type(char*type,int ipotype) +{ + int i = 0,typenumber = -1,tabsize; + if (ipotype == ID_OB) + { + char*nametab[24] = {"LocX","LocY","LocZ","dLocX","dLocY","dLocZ","RotX","RotY","RotZ","dRotX","dRotY","dRotZ","SizeX","SizeY","SizeZ","dSizeX","dSizeY","dSizeZ","Layer","Time","ColR","ColG","ColB","ColA"}; + tabsize = 24; + for(i = 0;iipo->blocktype); if (typenumber == -1) return (EXPP_ReturnPyObjError (PyExc_TypeError, "unknown type")); ptr = (IpoCurve*)MEM_callocN(sizeof(IpoCurve),name); - ptr->blocktype = 16975; + ptr->blocktype = ID_OB; ptr->totvert = 0; ptr->adrcode = typenumber; ptr->ipo = 2; @@ -295,6 +357,21 @@ static PyObject *Ipo_addCurve(C_Ipo *self, PyObject *args) return IpoCurve_CreatePyObject (ptr); } +static PyObject *Ipo_getCurve(C_Ipo *self, PyObject *args) +{ + int num = 0 , i = 0; + char*str; + IpoCurve *icu = 0; + if (!PyArg_ParseTuple(args, "s",&str)) + return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected string argument")); + puts(str); + for (icu=self->ipo->curve.first; icu; icu=icu->next){ + if (!strcmp(type_from_num(icu->adrcode, icu->blocktype),str))return IpoCurve_CreatePyObject(icu); + } + + Py_INCREF(Py_None); + return Py_None; +} static PyObject *Ipo_getCurves(C_Ipo *self) { @@ -523,7 +600,7 @@ static int IpoSetAttr (C_Ipo *self, char *name, PyObject *value) /*****************************************************************************/ static PyObject *IpoRepr (C_Ipo *self) { - return PyString_FromFormat("[Ipo \"%s\"]", self->ipo->id.name+2); + return PyString_FromFormat("[Ipo \"%s\" %d]", self->ipo->id.name+2,self->ipo->blocktype); } /* Three Python Ipo_Type helper functions needed by the Object module: */ @@ -536,15 +613,10 @@ static PyObject *IpoRepr (C_Ipo *self) PyObject *Ipo_CreatePyObject (Ipo *ipo) { C_Ipo *pyipo; - pyipo = (C_Ipo *)PyObject_NEW (C_Ipo, &Ipo_Type); - if (!pyipo) - return EXPP_ReturnPyObjError (PyExc_MemoryError, - "couldn't create C_Ipo object"); - + return EXPP_ReturnPyObjError (PyExc_MemoryError,"couldn't create C_Ipo object"); pyipo->ipo = ipo; - return (PyObject *)pyipo; } diff --git a/source/blender/python/api2_2x/Ipo.h b/source/blender/python/api2_2x/Ipo.h index 28e45e84ffb..c71a38dca85 100644 --- a/source/blender/python/api2_2x/Ipo.h +++ b/source/blender/python/api2_2x/Ipo.h @@ -93,6 +93,7 @@ static PyObject *Ipo_setBlocktype(C_Ipo *self, PyObject *args); static PyObject *Ipo_getRctf(C_Ipo *self); static PyObject *Ipo_setRctf(C_Ipo *self, PyObject *args); +static PyObject *Ipo_getCurve(C_Ipo *self, PyObject *args); static PyObject *Ipo_getCurves(C_Ipo *self); static PyObject *Ipo_addCurve(C_Ipo *self, PyObject *args); static PyObject *Ipo_getNcurves(C_Ipo *self); @@ -143,6 +144,8 @@ static PyMethodDef C_Ipo_methods[] = { "() - Return curval"}, {"getCurves", (PyCFunction)Ipo_getCurves, METH_NOARGS, "() - Return curval"}, + {"getCurve", (PyCFunction)Ipo_getCurve, METH_VARARGS, + "() - Return curval"}, {0} }; -- cgit v1.2.3