Revision: 16974 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16974 Author: khughes Date: 2008-10-08 18:37:33 +0200 (Wed, 08 Oct 2008)
Log Message: ----------- 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. Modified Paths: -------------- trunk/blender/source/blender/python/api2_2x/Object.c trunk/blender/source/blender/python/api2_2x/Particle.c trunk/blender/source/blender/python/api2_2x/doc/Object.py Modified: trunk/blender/source/blender/python/api2_2x/Object.c =================================================================== --- trunk/blender/source/blender/python/api2_2x/Object.c 2008-10-08 16:29:09 UTC (rev 16973) +++ trunk/blender/source/blender/python/api2_2x/Object.c 2008-10-08 16:37:33 UTC (rev 16974) @@ -342,9 +342,8 @@ 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 @@ /* 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,43 +1043,49 @@ /*****************************************************************************/ PyObject *Object_getParticleSys( BPy_Object * self ){ - ParticleSystem *blparticlesys = 0; + PyObject *list; + ParticleSystem *psys= NULL; Object *ob = self->object; - PyObject *partsyslist,*current; + int i= 0; - blparticlesys = ob->particlesystem.first; + list = PyList_New( BLI_countlist( &ob->particlesystem ) ); + if( !list ) + return EXPP_ReturnPyObjError( PyExc_MemoryError, + "PyList_New() failed" ); - partsyslist = PyList_New( 0 ); + for( psys=ob->particlesystem.first; psys; psys=psys->next ) + PyList_SET_ITEM( list, i++, ParticleSys_CreatePyObject( psys, ob ) ); - if (!blparticlesys) - return partsyslist; - -/* fixme: for(;;) */ - current = ParticleSys_CreatePyObject( blparticlesys, ob ); - PyList_Append(partsyslist,current); - Py_DECREF(current); - - while((blparticlesys = blparticlesys->next)){ - current = ParticleSys_CreatePyObject( blparticlesys, ob ); - PyList_Append(partsyslist,current); - Py_DECREF(current); - } - - 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; - id = (ID *)psys_new_settings("PSys", G.main); + if( !PyArg_ParseTuple( args, "|s", &name ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected a string or nothing" ); + 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(); psys->flag |= PSYS_ENABLED; Modified: trunk/blender/source/blender/python/api2_2x/Particle.c =================================================================== --- trunk/blender/source/blender/python/api2_2x/Particle.c 2008-10-08 16:29:09 UTC (rev 16973) +++ trunk/blender/source/blender/python/api2_2x/Particle.c 2008-10-08 16:37:33 UTC (rev 16974) @@ -138,7 +138,7 @@ /*****************************************************************************/ /* 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 @@ /*****************************************************************************/ /* 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 ); } /*****************************************************************************/ Modified: trunk/blender/source/blender/python/api2_2x/doc/Object.py =================================================================== --- trunk/blender/source/blender/python/api2_2x/doc/Object.py 2008-10-08 16:29:09 UTC (rev 16973) +++ trunk/blender/source/blender/python/api2_2x/doc/Object.py 2008-10-08 16:37:33 UTC (rev 16974) @@ -656,9 +656,13 @@ 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): _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs