Getting Corresponding IDs: code sample

Land Desktop Development ARX CPP SDK

 

Getting Corresponding IDs

The following sample demonstrates getting an entity's Oracle ID if its AutoCAD ID is known, and vice versa. It also demonstrates that round trips with corresponding IDs are reliable — that if you use an AutoCAD ID to get an Oracle ID, and then use the Oracle ID to get an AutoCAD ID, the two AutoCAD IDs are the same.

Note  The sample assumes an open project drawing containing imported entities. It also assumes that the connection object is actually connected to a database. Click "Connecting to an Oracle Spatial Database" for sample code.

#include "StdAfx.h"
#include "StdArx.h"
#include "AcMapOracleConnection.h"
#include "AcMapOracleIdentification.h"

BOOL Identification()
{

// Get the connection object
AcMapOracleConnection *pConnection = AcMapOracleGetConnection();

// Create an identification object
AcmapOracleIdentification *pId = new AcMapOracleIdentification(pConnection);

AcDbObjectId AcadId;
AcDbEntity *pEntity;
ads_name en;
ads_point pt;
unsigned long ulOracleID;

// Get an entity from the user
if((acedEntSel("\nSelect an entity: ", en , pt) == RTNORM))
{
   // Get the entity's AutoCAD ID
   acdbGetObjectId(AcadId, en);
   
   // Initialize the identification object with the AutoCAD ID
   bInit = pId->Init(AcadId);
   
   // Get the corresponding Oracle ID
   ulOracleID = pId->GetOracleID();
   
   char pBuf[100];
   
   // Get the entity's handle and print it to the AutoCAD Map text window
   if (Acad::eOk == acdbOpenAcDbEntity( pEntity, AcadId, AcDb::kForRead ))
   {
      AcadId.handle().getIntoAsciiBuffer(pBuf);
      acutPrintf("\nAcad handle sel:%s", pBuf);
      pEntity->close();
   }

   // Initialize the identification object with the Oracle ID
   bInit = pId->Init(ulOracleID);
   
   // Get the corresponding AutoCAD ID
   AcadId = pId->GetAcadID(
           acdbHostApplicationServices()->workingDatabase());
						
   // Get the entity's handle and print it to the AutoCAD Map text window
   if (Acad::eOk == acdbOpenAcDbEntity( pEntity, AcadId, AcDb::kForRead ))
   {
     AcadId.handle().getIntoAsciiBuffer(pBuf);
     acutPrintf("\nAcad handle sel:%s", pBuf);
     pEntity->close();
   }
}

acadSSFree(en);

}