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.
This commit is contained in:
Ken Hughes 2008-10-08 16:37:33 +00:00
parent bfe2759ceb
commit 5fd6e7e1b7
3 changed files with 43 additions and 33 deletions

@ -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;
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();

@ -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 );
}
/*****************************************************************************/

@ -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):