From 7040e6c157b53c844dc9e0a0c895f4a2167520cb Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Mon, 31 Oct 2005 14:05:47 +0000 Subject: -- patch submitted by Johnny Matthews which lets a user get an Ipo curve by its adrcode in addition to its string name (shape keys don't have fixed or unique string names, and they are stored in the key, not the Ipo). This will make it easier to later use constants from dictionaries to access a curve. --- source/blender/python/api2_2x/Ipo.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'source/blender/python/api2_2x/Ipo.c') diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c index 02a7749c59d..f0dffe3f0e5 100644 --- a/source/blender/python/api2_2x/Ipo.c +++ b/source/blender/python/api2_2x/Ipo.c @@ -970,22 +970,34 @@ static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args ) static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args ) { - char *str, *str1; - IpoCurve *icu = 0; - - if( !PyArg_ParseTuple( args, "s", &str ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected string argument" ) ); - - for( icu = self->ipo->curve.first; icu; icu = icu->next ) { - str1 = getIpoCurveName( icu ); - if( !strcmp( str1, str ) ) - return IpoCurve_CreatePyObject( icu ); - } - - Py_INCREF( Py_None ); - return Py_None; -} + char *str, *str1; + IpoCurve *icu = NULL; + int adrcode; + PyObject *thing; + + if( !PyArg_ParseTuple( args, "O", &thing ) ) + return EXPP_ReturnPyObjError(PyExc_TypeError, + "expected string or int argument" ); + + if(PyString_Check(thing)){ + str = PyString_AsString(thing); + for( icu = self->ipo->curve.first; icu; icu = icu->next ) { + str1 = getIpoCurveName( icu ); + if( !strcmp( str1, str ) ) + return IpoCurve_CreatePyObject( icu ); + } + } else if (PyInt_Check(thing)){ + adrcode = (short)PyInt_AsLong(thing); + for( icu = self->ipo->curve.first; icu; icu = icu->next ) { + if(icu->adrcode == adrcode) + return IpoCurve_CreatePyObject( icu ); + } + } else + return EXPP_ReturnPyObjError(PyExc_TypeError, + "expected string or int argument" ); + Py_INCREF( Py_None ); + return Py_None; +} static PyObject *Ipo_getCurves( BPy_Ipo * self ) { -- cgit v1.2.3