From f3ae4d0f4d0e89d07c7609cf38a7fbf11451cc90 Mon Sep 17 00:00:00 2001 From: Ken Hughes Date: Sat, 20 May 2006 16:52:11 +0000 Subject: [PATCH] ===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. --- source/blender/python/api2_2x/Mesh.c | 8 ++++++++ source/blender/python/api2_2x/Mesh.h | 1 + source/blender/python/api2_2x/doc/Mesh.py | 2 ++ 3 files changed, 11 insertions(+) diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 76183c75a68..5f1f8b8314f 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -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; } diff --git a/source/blender/python/api2_2x/Mesh.h b/source/blender/python/api2_2x/Mesh.h index ada47b0927c..19518e7f0b6 100644 --- a/source/blender/python/api2_2x/Mesh.h +++ b/source/blender/python/api2_2x/Mesh.h @@ -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 */ diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py index ab182dbddb5..1aafd6b080b 100644 --- a/source/blender/python/api2_2x/doc/Mesh.py +++ b/source/blender/python/api2_2x/doc/Mesh.py @@ -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):