Issue
Is it possible to get the objectID by its PnPID or RowID?
Solution
Yes. It is a two steps process, because there is a one-to-many possibility.
PnPID and RowID are the same thing.
1. DataLinksManager.FindAcPpObjectIds(rowId) –> collection of PpObjectId
2. DataLinksManager.MakeAcDbObjectId(ppObjId) –> converts PpObjectId to ObjectId
There are various flavors of those functions. The main point to get across is that multiple AcDbObjectIds may be linked to a single RowID.
Here is a sample:
// Conversions of IDs back and forth. //------------------------------------------------------------------ [CommandMethod("TestIds")] public static void TestIds() { // Prepare to the work: Let's get some entity's ObjectId Database db = Application.DocumentManager.MdiActiveDocument.Database; DataLinksManager dlm = DataLinksManager.GetManager(db); Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ObjectId entId = ed.GetEntity("Pick a P&ID item: ").ObjectId; // Now get the PnPID (i.e. PpObjectId) // from the selected entity's ObjectId PpObjectId pnpId = dlm.MakeAcPpObjectId(entId); // Now let's do an opposite action - find ObjectId(s) of the entity int rowId1 = dlm.FindAcPpRowId(entId); // You can use ObjectId int rowId2 = dlm.FindAcPpRowId(pnpId); // or PpObjectId // rowId1 and rowId2 are always equal PpObjectIdArray ids = dlm.FindAcPpObjectIds(rowId1); // NOTE: It returns a COLLECTION of AcPpObjectId! // I.e., multiple AcDbObjectIds may be linked to a single RowID // Now find the ObjectID for each PpObjectId foreach (PpObjectId ppid in ids) { ObjectId oid = dlm.MakeAcDbObjectId(ppid); ed.WriteMessage("n oid=" + oid.ToString()); } } // TestIds()

Leave a Reply