Example #1
0
        public static void formatStringsAndAnnotations()
        {
            //Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
            //// DataLinksManager dlm = DataLinksManager.GetManager(db);
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            //ObjectId entId = ed.GetEntity("Pick an SLINE TargetObject: ").ObjectId;

            ////Evaluate

            //String sEval = Autodesk.ProcessPower.PnPCommonDbx.FormatStringUtils.Evaluate(
            //   "#(TargetObject.LineNumber^@NNN) - #(Project.General.Project_Name)",
            //   entId
            //);

            //ed.WriteMessage(sEval);

            // Need to figure out how to get the Annotation Class and
            // AnnotationFormatToolsUtil - This is out of date!
            // use FormatStringUtils instead.
            ObjectId annotationId = ed.GetEntity("Pick Annotation: ").ObjectId;

            Annotation an = new Annotation(annotationId);

            for (int ifs = 0; ifs < an.NumFormatStrings; ifs++)
            {
                String   sfs      = an.GetFormatString(ifs);
                ObjectId targetId = an.TargetId;
                // AnnotationFormatToolsUtil oUtil = new AnnotationFormatToolsUtil();
                //  FormatStringUtils oUtil = new FormatStringUtils();

                //Evaluate
                // String seval = oUtil.Evaluate(sfs, targetId); //WB commented
                String seval = FormatStringUtils.Evaluate(sfs, targetId); //WB added
                ed.WriteMessage(seval + " (" + sfs + ").");
            }
        }
Example #2
0
        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());
            }
        }