===Python API===

Something to try making import/export script writers happy; Mesh.New() will
not create a new Blender mesh datablock unless the mesh is linked to an
object.
This commit is contained in:
Ken Hughes 2006-05-20 16:52:11 +00:00
parent befd007511
commit f3ae4d0f4d
3 changed files with 11 additions and 0 deletions

@ -6907,6 +6907,12 @@ static int Mesh_setActiveGroup( BPy_Mesh * self, PyObject * arg )
static void Mesh_dealloc( BPy_Mesh * self )
{
Mesh *mesh = self->mesh;
/* if the mesh is new and has no users, delete it */
if( self->new && !mesh->id.us )
free_libblock( &G.main->mesh, mesh );
PyObject_DEL( self );
}
@ -7149,6 +7155,7 @@ static PyObject *M_Mesh_New( PyObject * self_unused, PyObject * args )
obj->mesh = mesh;
obj->object = NULL;
obj->new = 1;
return (PyObject *)obj;
}
@ -7403,6 +7410,7 @@ PyObject *Mesh_CreatePyObject( Mesh * me, Object *obj )
nmesh->mesh = me;
nmesh->object = obj;
nmesh->new = 0;
return ( PyObject * ) nmesh;
}

@ -115,6 +115,7 @@ typedef struct {
PyObject_HEAD /* required python macro */
Mesh *mesh;
Object *object;
char new; /* was mesh created or already existed? */
} BPy_Mesh;
/* PROTOS */

@ -132,6 +132,8 @@ def New(name='Mesh'):
@param name: The name of the mesh data object.
@rtype: Mesh
@return: a new Blender mesh.
@note: if the mesh is not linked to an object, its datablock will be deleted
when the object is deallocated.
"""
def Mode(mode=0):