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.
- Include the necessary
header files:
#include "StdAfx.h"
#include "StdArx.h"
#include <MapArxApi.h>
#include <MapProj.h>
#include <MapODIterator.h>
- 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;
- Create an AutoCAD Map 3D
session and get the top level objects.
mapApi = AcMapGetSession();
mapApi->GetProject(pProj);
pProj->GetODContainer(pODCont);
- 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");
return;}
acdbGetObjectId(eId, ename);
- Get a record iterator
and initialize it for reading.
pODCont->GetObjectODRecordIterator (pIter);
pIter->Init (eId, AcMap::kOpenForRead, Adesk::kFalse);
- Use the record iterator
to count records attached to the object. Print the results.
recQuantity = pIter->CountRecords();
acutPrintf("\nObject has %d records attached.", recQuantity);
- Delete the iterator when
you're finished with it.
if (pIter) delete pIter;