From 26ef99157eaba677ccbade3b99dd6a990ca48474 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 13 Nov 2006 17:37:01 +0000 Subject: [PATCH] made mesh.getFromObject() accept a python object as well as the object name. accepting the name only was causing big problems when exporting library data, because duplicate names are possible the wrong data was exporting. --- release/scripts/bpymodules/BPyMesh.py | 4 ++-- source/blender/python/api2_2x/Mesh.c | 22 ++++++++++++++++------ source/blender/python/api2_2x/doc/Mesh.py | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index d0d48504d9d..214fe4175eb 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -315,7 +315,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru tempob= None if apply_modifiers or type != 'Mesh': try: - mesh.getFromObject(ob.name) + mesh.getFromObject(ob) except: return None @@ -327,7 +327,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru tempob= Blender.Object.New('Mesh') tempob.shareFrom(ob) scn.link(tempob) - mesh.getFromObject(tempob.name) + mesh.getFromObject(tempob) scn.unlink(tempob) if type == 'Mesh': diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 79b09563efd..528fb9e87f5 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -5704,7 +5704,8 @@ static PyObject *Mesh_findEdges( PyObject * self, PyObject *args ) static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) { - Object *ob; + Object *ob = NULL; + PyObject *object_arg; char *name; ID tmpid; Mesh *tmpmesh; @@ -5714,16 +5715,25 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) Object *tmpobj = NULL; int cage = 0, render = 0, i; - if( !PyArg_ParseTuple( args, "s|i", &name, &cage, &render ) ) + if( !PyArg_ParseTuple( args, "O|i", &object_arg, &cage, &render ) ) { return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string and optional integer arguments" ); - + "expected object or string and optional integer arguments" ); + } + + if ( PyString_Check( object_arg ) ) { + name = PyString_AsString ( object_arg ); + ob = ( Object * ) GetIdFromList( &( G.main->object ), name ); + } else if ( Object_CheckPyObject(object_arg) ) { + ob = (( BPy_Object * ) object_arg)->object; + } else { + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected object or string and optional integer arguments" ); + } + if( cage != 0 && cage != 1 ) return EXPP_ReturnPyObjError( PyExc_ValueError, "cage value must be 0 or 1" ); - /* find the specified object */ - ob = ( Object * ) GetIdFromList( &( G.main->object ), name ); if( !ob ) return EXPP_ReturnPyObjError( PyExc_AttributeError, name ); diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py index 10098759951..cb0226bc39d 100644 --- a/source/blender/python/api2_2x/doc/Mesh.py +++ b/source/blender/python/api2_2x/doc/Mesh.py @@ -746,7 +746,7 @@ class Mesh: @type texMesh: Mesh or None """ - def getFromObject(name,cage=0, render=0): + def getFromObject(object, cage=0, render=0): """ Replace the mesh's existing data with the raw mesh data from a Blender Object. This method supports all the geometry based objects (mesh, text, @@ -758,8 +758,8 @@ class Mesh: be multiplied by the object's 4x4 transform matrix (see L{transform}). @note: The objects materials will not be copied into the existing mesh, however the face material indices will match the material list of the original data. - @type name: string - @param name: name of the Blender object which contains the geometry data. + @type name: blender object or string + @param name: The Blender object or its name, which contains the geometry data. @type cage: int @param cage: determines whether the original vertices or derived vertices @type render: int