Getting Corresponding IDs
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 Database" for sample code.
Connecting to an Oracle Spatial Database Oracle and AutoCAD IDs Getting corresponding IDs Code samples
#include "StdAfx.h"#include "StdArx.h"#include "AdMapOracleConnection.h"#include "AdMapOracleIdentification.h"BOOL Identification(){// Get connection pointerAcMapOSEConnection *pConnection = AcMapOSEGetConnection();// Declare identification objectAcMapOSEObject *pId = new AcMapOSEObject(pConnection);AcDbObjectId AcadId;AcDbEntity *pEntity;ads_name en;ads_point pt;OValue OracleID;char pBuf[100];// Get a drawing object (entity) from the userif(acedEntSel("\nSelect an entity: ", en , pt) == RTNORM){// Get the entity's AutoCAD IDacdbGetObjectId(AcadId, en);// Get the entity's handle and print it to the AutoCAD Map 3D text windowif (Acad::eOk == acdbOpenAcDbEntity( pEntity, AcadId, AcDb::kForRead )){AcadId.handle().getIntoAsciiBuffer(pBuf);acutPrintf("\nAcad handle sel:%s",pBuf);pEntity->close();}// Initialize identification object with AutoCAD IDbInit = pId->Init(AcadId);// Get the entity's corresponding Oracle IDOracleID = pId->GetOracleID();// Again initialize identification object, now with Oracle IDbInit = pId->Init(OracleID);// Get the entity's corresponding AutoCAD IDAcadId = pId->GetAcadID();// Get the entity's handle and print it to the AutoCAD Map 3D text window,// and note that it is the same entity as beforeif (Acad::eOk == AcDbOpenAcDbEntity( pEntity, AcadId, AcDb::kForRead )){AcadId.handle().getIntoAsciiBuffer(pBuf);acutPrintf("\nAcad handle sel:%s",pBuf);pEntity->close();}// You can get other information about this entity besides its IDs// FeatureName()char *pName;strcpy(pName,pId->FeatureName());acutPrintf("\nFeatureName = %s\n",pName);// IsInEditSet()if(pId->IsInEditSet()){acutPrintf("\nObject is locked\n");}else{acutPrintf("\nObject is not locked\n");}// IsModified()if(pId->IsModified()){acutPrintf("\nObject has been modified\n");}else{acutPrintf("\nObject has not been modified\n");}// IsErased()if(pId->IsErased()){acutPrintf("\nObject has been erased\n");}else{acutPrintf("\nObject has not been erased\n");}// AddToEditSet()if(pId->AddToEditSet()){acutPrintf("\nObject added to EditSet\n");}else{acutPrintf("\nObject not added to EditSet\n");}// RemoveFromEditSet()if(pId->removeFromEditSet()){acutPrintf("\nObject removed from EditSet\n");}else{acutPrintf("\nObjects not removed from EditSet\n");}// Version()unsigned long ulVersion;ulVeresion = pId->Version();// IsUpToDate()if(pId->IsUpToDate()){acutPrintf("\nObject is up to date\n");}else{acutPrintf("\nObject has been modified since importing it\n");}// WhoHasIt()unsigned long ulUserId;std::string strNtuser, strDbUser, strMapUser, strComputer, strLoginTime;if(pId->WhoHasIt(ulUserId,strNtUser,strDbUser,strMapUser,strComputer,strLoginTime)){acutPrintf("\nUserId = %ul\n",ulUserId);acutPrintf("\nNtUser = %s\n",strNtUser.data());acutPrintf("\nDbuser = %s\n",strDbUser.data());acutPrintf("\nMapUser = %s\n",strMapUser.data());acutPrintf("\nComputer = %s\n",strcomputerr.data());acutPrintf("\nLoginTime = %s\n",strComputer.data());}else{acutPrintf("\nObject is not locked\n");}} // if(acedEntSel("\nSelect an entity: ", en , pt) == RTNORM)acadSSFree(en);delete pId;}