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.
This commit is contained in:
Campbell Barton 2006-11-13 17:37:01 +00:00
parent 745aaf01c6
commit 26ef99157e
3 changed files with 21 additions and 11 deletions

@ -315,7 +315,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru
tempob= None tempob= None
if apply_modifiers or type != 'Mesh': if apply_modifiers or type != 'Mesh':
try: try:
mesh.getFromObject(ob.name) mesh.getFromObject(ob)
except: except:
return None return None
@ -327,7 +327,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru
tempob= Blender.Object.New('Mesh') tempob= Blender.Object.New('Mesh')
tempob.shareFrom(ob) tempob.shareFrom(ob)
scn.link(tempob) scn.link(tempob)
mesh.getFromObject(tempob.name) mesh.getFromObject(tempob)
scn.unlink(tempob) scn.unlink(tempob)
if type == 'Mesh': if type == 'Mesh':

@ -5704,7 +5704,8 @@ static PyObject *Mesh_findEdges( PyObject * self, PyObject *args )
static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args )
{ {
Object *ob; Object *ob = NULL;
PyObject *object_arg;
char *name; char *name;
ID tmpid; ID tmpid;
Mesh *tmpmesh; Mesh *tmpmesh;
@ -5714,16 +5715,25 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args )
Object *tmpobj = NULL; Object *tmpobj = NULL;
int cage = 0, render = 0, i; 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, 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 ) if( cage != 0 && cage != 1 )
return EXPP_ReturnPyObjError( PyExc_ValueError, return EXPP_ReturnPyObjError( PyExc_ValueError,
"cage value must be 0 or 1" ); "cage value must be 0 or 1" );
/* find the specified object */
ob = ( Object * ) GetIdFromList( &( G.main->object ), name );
if( !ob ) if( !ob )
return EXPP_ReturnPyObjError( PyExc_AttributeError, name ); return EXPP_ReturnPyObjError( PyExc_AttributeError, name );

@ -746,7 +746,7 @@ class Mesh:
@type texMesh: Mesh or None @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 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, 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}). be multiplied by the object's 4x4 transform matrix (see L{transform}).
@note: The objects materials will not be copied into the existing mesh, @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. however the face material indices will match the material list of the original data.
@type name: string @type name: blender object or string
@param name: name of the Blender object which contains the geometry data. @param name: The Blender object or its name, which contains the geometry data.
@type cage: int @type cage: int
@param cage: determines whether the original vertices or derived vertices @param cage: determines whether the original vertices or derived vertices
@type render: int @type render: int