public static void getDataUsingString() { Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; try { PlantProject mainPrj = PlantApplication.CurrentProject; Project prj = mainPrj.ProjectParts["PnId"]; DataLinksManager dlm = prj.DataLinksManager; ObjectId entId = ed.GetEntity("Pick a P&ID item: ").ObjectId; // x.x Declare a variable as a PpObjectId and instantiate it // using the MakeAcPpObjectId method of the DataLinksManager // from step 3.x. Pass in the ObjectId from step 3.4. PpObjectId pnpId = dlm.MakeAcPpObjectId(entId); // x.x Now let's do an opposite action that we did in step 3.5 // Now we will get the ObjectId(s) of the entity from the PpObjectId // from step 3.x. Declare an int and make it equal to the // return from the FindAcPpRowId of the DataLinksManager from // step 3.x. 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() + "\n"); // Evaluate the next two lines are not in the DevNote: String sEval = "\n LineNumber = "; sEval += FormatStringUtils.Evaluate ("#(TargetObject.LineNumber^@NNN)", oid); // - #(Project.General.Project_Name)", oid); sEval += "\n Project_Name = "; sEval += FormatStringUtils.Evaluate("#(Project.General.Project_Name)", oid); ed.WriteMessage(sEval); // String sEval2 = "\n TargeObject.Tag = "; // String sTestIsValid = "#(TargetObject.Tag) - #(=TargetObject.Tag)"; //String sTestIsValid = "#(TargetObject.Tag)"; // - #(=TargetObject.Tag)"; String sTestIsValid = "#(GenericRotaryValve.Manufacturer)"; if (FormatStringUtils.IsValid(sTestIsValid)) { String sEval2 = "\n Generic Rotary Valve Manufacturer = "; // sEval2 += FormatStringUtils.Evaluate("#(TargetObject.Tag) - #(=TargetObject.Tag)"); sEval2 += FormatStringUtils.Evaluate(sTestIsValid, oid); ed.WriteMessage(sEval2); } } } catch (System.Exception ex) { ed.WriteMessage(ex.ToString()); } }
public static void convertIds() { Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; try { // 3.1 Declare a variable as a PlantProject and instantiate // it using the CurrentProject of PlantApplication. PlantProject mainPrj = PlantApplication.CurrentProject; // 3.2 Declare a variable as a Project and instantiate it // using the ProjectParts property of the PlantProject from // step 3.1. for the strName property [] use "PnId" Project prj = mainPrj.ProjectParts["PnId"]; //wb testing, commented out the line above // Project prj = mainPrj.ProjectParts["Piping"]; // 3.3 Declare a DataLinksManager variable and instantiate it // using the DataLinksManager property of the Project from // step 3.2 DataLinksManager dlm = prj.DataLinksManager; // 3.4 Declare a variable as an ObjectId. Instantiate it // use the GetEntity method of the Editor from above. (ed) // Use the ObjectId property. ObjectId entId = ed.GetEntity("Pick a P&ID item: ").ObjectId; // 3.5 Get the Row Id of the entity from the ObjectId // from step 3.4. Declare an int and make it equal to the // return from the FindAcPpRowId of the DataLinksManager from // step 3.3. pass in the ObjectId from step 3.4. // Note: The int for the Row Id from this step and the Row Id from // step 7 will be the same, even though we are using ObjectId here // and PpObjectId in step 3.7 int rowId1 = dlm.FindAcPpRowId(entId); // 3.6 Declare a variable as a PpObjectId and instantiate it // using the MakeAcPpObjectId method of the DataLinksManager // from step 3.3. Pass in the ObjectId from step 3.4. PpObjectId ppObjId = dlm.MakeAcPpObjectId(entId); // 3.7 Now we will get the Row Id of the entity from the PpObjectId // from step 3.5. Declare an int and make it equal to the // return from the FindAcPpRowId of the DataLinksManager from // step 3.3. Pass in the PpObjectId 3.6 int rowId2 = dlm.FindAcPpRowId(ppObjId); // 3.8 Use the WriteMessage function of the editor (ed) and print // the values of the int from step 3.7 and 3.5 ed.WriteMessage("rowId1 = " + rowId1.ToString() + " rowId2 = " + rowId2); // 3.9 Declare a variable as a PpObjectIdArray. Instantiate it // using the FindAcPpObjectIds method of the DataLinksManager from // step 3.3. Pass in the row id from step or 3.5. (or step 3.7) // NOTE: FindAcPpObjectIds returns a COLLECTION of AcPpObjectId. // I.e., multiple AcDbObjectIds may be linked to a single RowID PpObjectIdArray ids = dlm.FindAcPpObjectIds(rowId1); // 3.10 Use a foreach and iterate through the PpObjectId in the // PpObjectIdArray from step 3.9. // Note: put the closing curly brace below Step 3.12 foreach (PpObjectId ppid in ids) { // 3.11 Declare a variable as an ObjectId Instantiate it using // the MakeAcDbObjectId variable of the DataLinksManager from // step 3.3. ObjectId oid = dlm.MakeAcDbObjectId(ppid); // 3.12 Use the WriteMessage function of the editor (ed) and print // the value of the ObjectId form step 3.11 // Build, debug and test this code. (Command "ConvertIds") // Note: Continue to step 3.13 below ed.WriteMessage("\n oid = " + oid.ToString() + "\n"); } } catch (System.Exception ex) { ed.WriteMessage(ex.ToString()); } }