Traversing Object Data

AutoCAD Map 3D ObjectARX

Traversing Object Data

The following sample iterates all of an object's records using AcMapODContainer::GetObjectODRecordIterator.

You can also iterate only those records that are contained in a specified table using AcMapODTable::GetObjectODRecordIterator.

To traverse records

  1. Include the necessary header files:
    #include "StdAfx.h"
    #include "StdArx.h"
    #include <MapArxApi.h>
    #include <MapProj.h>
    #include <MapODIterator.h>
  2. Declare variables.
    int retCode = FALSE;
    ads_name ename;
    ads_point spt;
    AcDbObjectId eId;
    int recQuantity = 0;
    AcMapSession *mapApi = NULL;
    AcMapProject *pProj = NULL;
    AcMapODContainer *pODCont = NULL;
    AcMapODRecordIterator *pIter = NULL;
  3. Create an AutoCAD Map 3D session and get the top level objects.
    mapApi = AcMapGetSession();
  4. Use ADS functions to prompt user to select an object, and convert the entity name of the selected object to an object ID for initializing the iterator in the next step.
    retCode = acedEntSel(NULL, ename, spt); 
    if (retCode != RTNORM) { 
    acutPrintf("\nNo object selected.\n"); 
    acdbGetObjectId(eId, ename);
  5. Get a record iterator and initialize it for reading.
    pODCont->GetObjectODRecordIterator (pIter);
    pIter->Init (eId, AcMap::kOpenForRead, Adesk::kFalse);
  6. Use the record iterator to count records attached to the object. Print the results.
    recQuantity = pIter->CountRecords();
    acutPrintf("\nObject has %d records attached.", recQuantity); 
  7. Delete the iterator when you're finished with it.
    if (pIter) delete pIter;