diff options
author | Ken Hughes <khughes@pacific.edu> | 2008-10-08 20:37:33 +0400 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2008-10-08 20:37:33 +0400 |
commit | 5fd6e7e1b79271cb450c21a0632d93f4b4a68ab1 (patch) | |
tree | 7c034e6b5acc4f420ab941e3ae047ab50b448dd2 /source/blender/python | |
parent | bfe2759ceb16be058041ddc402fc415f2d8b5669 (diff) |
Python API
----------
Add optional string argument to Object.newParticleSystem() method, so that
objects can link to existing particle systems (if the name of the particle
system is known). Also cleans up some code in Object.c which accesses the
particle sys listbase.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 57 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Particle.c | 11 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Object.py | 8 |
3 files changed, 43 insertions, 33 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 4495dc6c655..a6ee9b7d540 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -342,9 +342,8 @@ static int setupSB(Object* ob); /*Make sure Softbody Pointer is initialized */ static int setupPI(Object* ob); static PyObject *Object_getParticleSys( BPy_Object * self ); -/* fixme Object_newParticleSys( self, default-partsys-name ) */ static PyObject *Object_addVertexGroupsFromArmature( BPy_Object * self, PyObject * args); -static PyObject *Object_newParticleSys( BPy_Object * self ); +static PyObject *Object_newParticleSys( BPy_Object * self, PyObject * args ); static PyObject *Object_buildParts( BPy_Object * self ); static PyObject *Object_clearIpo( BPy_Object * self ); static PyObject *Object_clrParent( BPy_Object * self, PyObject * args ); @@ -478,7 +477,7 @@ static PyMethodDef BPy_Object_methods[] = { /* name, method, flags, doc */ {"getParticleSystems", ( PyCFunction ) Object_getParticleSys, METH_NOARGS, "Return a list of particle systems"}, - {"newParticleSystem", ( PyCFunction ) Object_newParticleSys, METH_NOARGS, + {"newParticleSystem", ( PyCFunction ) Object_newParticleSys, METH_VARARGS, "Create and link a new particle system"}, {"addVertexGroupsFromArmature" , ( PyCFunction ) Object_addVertexGroupsFromArmature, METH_VARARGS, "Add vertex groups from armature using the bone heat method"}, @@ -1044,42 +1043,48 @@ static PyObject *M_Object_Duplicate( PyObject * self_unused, /*****************************************************************************/ PyObject *Object_getParticleSys( BPy_Object * self ){ - ParticleSystem *blparticlesys = 0; + PyObject *list; + ParticleSystem *psys= NULL; Object *ob = self->object; - PyObject *partsyslist,*current; - - blparticlesys = ob->particlesystem.first; - - partsyslist = PyList_New( 0 ); - - if (!blparticlesys) - return partsyslist; + int i= 0; -/* fixme: for(;;) */ - current = ParticleSys_CreatePyObject( blparticlesys, ob ); - PyList_Append(partsyslist,current); - Py_DECREF(current); + list = PyList_New( BLI_countlist( &ob->particlesystem ) ); + if( !list ) + return EXPP_ReturnPyObjError( PyExc_MemoryError, + "PyList_New() failed" ); - while((blparticlesys = blparticlesys->next)){ - current = ParticleSys_CreatePyObject( blparticlesys, ob ); - PyList_Append(partsyslist,current); - Py_DECREF(current); - } + for( psys=ob->particlesystem.first; psys; psys=psys->next ) + PyList_SET_ITEM( list, i++, ParticleSys_CreatePyObject( psys, ob ) ); - return partsyslist; + return list; } -PyObject *Object_newParticleSys( BPy_Object * self ){ +PyObject *Object_newParticleSys( BPy_Object * self, PyObject * args ) { ParticleSystem *psys = 0; ParticleSystem *rpsys = 0; ModifierData *md; ParticleSystemModifierData *psmd; Object *ob = self->object; -/* char *name = NULL; optional name param */ + char *name = NULL; ID *id; - int nr; + int nr; + + if( !PyArg_ParseTuple( args, "|s", &name ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected a string or nothing" ); - id = (ID *)psys_new_settings("PSys", G.main); + if( name ) { + for( id= G.main->particle.first; id; id= id->next ) { + if( !strcmp( name, id->name + 2 ) ) + break; + } + if( !id ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "specified particle system not found" ); + else + id->us++; + } else + id = (ID *)psys_new_settings("PSys", G.main); psys = MEM_callocN(sizeof(ParticleSystem), "particle_system"); psys->pointcache = BKE_ptcache_add(); diff --git a/source/blender/python/api2_2x/Particle.c b/source/blender/python/api2_2x/Particle.c index 893ee077d67..bbdc3942fc7 100644 --- a/source/blender/python/api2_2x/Particle.c +++ b/source/blender/python/api2_2x/Particle.c @@ -138,7 +138,7 @@ static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ); /*****************************************************************************/ /* Python Effect_Type callback function prototypes: */ /*****************************************************************************/ -static PyObject *ParticleSys_repr( void ); +static PyObject *ParticleSys_repr( BPy_PartSys * self ); /*****************************************************************************/ /* The following string definitions are used for documentation strings. */ @@ -415,13 +415,14 @@ PyTypeObject ParticleSys_Type = { /*****************************************************************************/ /* Function: PARTICLESYS_repr */ -/* Description: This is a callback function for the BPy_Effect type. It */ -/* builds a meaninful string to represent effcte objects. */ +/* Description: This is a callback function for the BPy_PartSys type. It */ +/* builds a meaningful string to represent effect objects. */ /*****************************************************************************/ -static PyObject *ParticleSys_repr( void ) +static PyObject *ParticleSys_repr( BPy_PartSys * self ) { - return PyString_FromString( "ParticleSys" ); + return PyString_FromFormat( "ParticleSys \"%s\"", + self->psys->part->id.name+2 ); } /*****************************************************************************/ diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index d56a547911e..c5ce7a4d2bf 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -656,9 +656,13 @@ class Object: Return a list of particle systems linked to this object (see Blender.Particle). """ - def newParticleSystem(): + def newParticleSystem(name = None): """ - Link a new particle system (see Blender.Particle). + Link a particle system (see Blender.Particle). If no name is + given, a new particle system is created. If a name is given and a + particle system with that name exists, it is linked to the object. + @type name: string + @param name: The name of the requested Particle system (optional). """ def addVertexGroupsFromArmature(object): |