[Bf-python] object.getDataName() - Implimented

Campbell Barton cbarton at metavr.com
Sat Jan 29 11:51:15 CET 2005


Hi, I was perplexed that There was no way to get the name of all the 
meshs without doing a getData- Which can be slow with large mesh's.
Sombody mentioned a NMesh.GetNames() or some such thing, but I thaught 
this would be more usefill.
As well as having
ob.getData(), I added
ob.getDataName(),
 This can be used with getType() to  find unique data and generally find 
look at the data your objects are using without actually loading them 
into memory.
I dont have CVS but if sombody wants to add this under getData() in 
Object.c, Id be qhute pleased :)

- Cam







static PyObject *Object_getDataName( BPy_Object * self )
{
    Object *object = self->object;
    PyObject *attr = NULL;
   
    /* do we need all of these */
    bArmature *arm;
    Camera *cam;
    Curve *cu;
    Image *image;
    Ipo *ipo;
    Lamp *lamp;
    Lattice *lt;
    Mesh *me;
    MetaBall *mball;
    Object *ob;
    Text *text;
   
    /* if there's no obdata, return none */
    if( object->data == NULL ) {
        Py_INCREF( Py_None );
        return ( Py_None );
    }
   
    switch ( object->type ) {
    case OB_ARMATURE:
        arm = object->data;
        attr = Py_BuildValue( "s", arm->id.name + 2 );       
        break;
    case OB_CAMERA:
        cam = object->data;
        attr = Py_BuildValue( "s", cam->id.name + 2 );       
        break;
    case OB_CURVE:
        cu = object->data;
        attr = Py_BuildValue( "s", cu->id.name + 2 );
        break;
    case ID_IM:
        image = object->data;
        attr = Py_BuildValue( "s", image->id.name + 2 );
        break;
    case ID_IP:
        ipo = object->data;
        attr = Py_BuildValue( "s", ipo->id.name + 2 );       
        break;
    case OB_LAMP:
        lamp = object->data;
        attr = Py_BuildValue( "s", lamp->id.name + 2 );       
        break;
    case OB_LATTICE:
        lt = object->data;
        attr = Py_BuildValue( "s", lt->id.name + 2 );
        break;
    case ID_MA:
        break;
    case OB_MESH:
        me = object->data;
        attr = Py_BuildValue( "s", me->id.name + 2 );
        break;
    case ID_MB:
        mball = object->data;
        attr = Py_BuildValue( "s", mball->id.name + 2 );
        break;   
    case ID_OB:
        ob = object->data;
        attr = Py_BuildValue( "s", ob->id.name + 2 );
        break;
    case ID_SCE:
        break;
    case ID_TXT:
        text= object->data;
        attr = Py_BuildValue( "s", text->id.name + 2 );
        break;
    case ID_WO:
        break;
    default:
        break;
    }   

    if( attr )
        return ( attr );
   
    Py_INCREF( Py_None );
    return ( Py_None );
}



-- 
Campbell J Barton

Sierra Suites Hotel
32 Fourth Av Waltham, Room 103
phone: 781 622 1900
mobile: 617 935 6773

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241




More information about the Bf-python mailing list