Exemplo n.º 1
0
        public ExportPoints(PointGroupCollection PointGroups, string SourceFile)
        {
            InitializeComponent();
            foreach (ObjectId group in PointGroups)
            {
                PointGroup pointGroup = (PointGroup)group.GetObject(OpenMode.ForRead);
                if (pointGroup.Name.ToLower() != "_all points" && pointGroup.Name.ToLower() != "no display")
                {
                    lbGroups.Items.Add(pointGroup.Name);
                }
            }

            FolderPath = SourceFile + "\\Comp";

            this.DialogResult = DialogResult.Cancel;
        }
        public static void ImportJobPoints()
        {
            var      doc = AcApp.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            var           jobNumber = Functions.GetJobNumber(doc);
            SelectionForm form      = new SelectionForm(jobNumber);
            var           ret       = AcApp.ShowModalDialog(form);

            if (ret == DialogResult.Cancel)
            {
                ed.WriteMessage("Job import canceled by user.");
                return;
            }
            else
            {
                ed.WriteMessage($"Import Job list: Count - {form.SelectedFiles.Count} | Filtered - {form.FilterPoints} | X-ref attach - {form.AttachXref}" + Environment.NewLine);
                List <List <C3DPoint> > pointList = IntFunctions.ProcessFiles(form.SelectedFiles);

                //Actually do the things
                using (Transaction trans = ed.Document.Database.TransactionManager.StartTransaction())
                {
                    List <CogoPoint> existingPoints = new List <CogoPoint> {
                    };
                    CogoPointCollection cogoPoints  = CivilApplication.ActiveDocument.CogoPoints;
                    foreach (var cogoPointObj in cogoPoints)
                    {
                        CogoPoint cogoPointItem = cogoPointObj.GetObject(OpenMode.ForWrite) as CogoPoint;
                        existingPoints.Add(cogoPointItem);
                    }

                    string confirmed = "";

                    for (int i = 0; i < pointList.Count; i++)
                    {
                        var points     = pointList[i];
                        int pointcount = 0;
                        foreach (var newPoint in points)
                        {
                            if (existingPoints.Where(pn => pn.PointNumber == newPoint.PointNumber).Count() == 0)
                            {
                                Point3d   point   = newPoint.Coordinate;
                                ObjectId  pointId = cogoPoints.Add(point, false);
                                CogoPoint cogop   = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                                cogop.PointNumber    = newPoint.PointNumber;
                                cogop.RawDescription = newPoint.Decsription;
                                cogop.StyleId        = ObjectId.Null;
                                cogop.LabelStyleId   = ObjectId.Null;
                                existingPoints.Add(cogop);
                                confirmed += $"{newPoint.PointNumber}, ";
                                pointcount++;
                            }
                            else
                            {
                                /*if (points.Where(pn => pn.RawDescription == (string)newPoint[4]).Count() == 0)
                                 * {
                                 *  MessageBox.Show("A point with a conflicting point number was detected. You can renumber this.");
                                 * }
                                 * else
                                 * {
                                 *  MessageBox.Show("A point with a conflicting point number and description was detected. Ingoring a duplicate point");
                                 * }*/
                            }
                        }
                        //TODO: Add more fuctionality to point group.

                        string filename = Path.GetFileNameWithoutExtension(form.SelectedFiles[i]);
                        ed.WriteMessage($"Successfully imported {pointcount} points." + Environment.NewLine);
                        if (form.AttachXref)
                        {
                            string folder  = Path.GetDirectoryName(form.SelectedFiles[i]);
                            string CADFile = Path.Combine(folder, filename + ".dwg");
                            if (File.Exists(Path.Combine(folder, filename + ".dwg")))
                            {
                                //Getting the layer object
                                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
                                if (!lt.Has("G-HH-XREF"))
                                {
                                    LayerTableRecord ltr = new LayerTableRecord
                                    {
                                        Name     = "G-HH-XREF",
                                        Color    = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7),
                                        IsFrozen = false,
                                        ViewportVisibilityDefault = true
                                    };

                                    ObjectId ltId = lt.Add(ltr);
                                    trans.AddNewlyCreatedDBObject(ltr, true);
                                }

                                var xId = db.AttachXref(CADFile, filename);
                                if (xId.IsValid)
                                {
                                    var btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                                    var br  = new BlockReference(Point3d.Origin, xId)
                                    {
                                        Layer = "G-HH-XREF"
                                    };
                                    btr.AppendEntity(br);
                                    trans.AddNewlyCreatedDBObject(br, true);
                                }
                            }
                            ed.WriteMessage($"Successfully attached {filename} CAD file." + Environment.NewLine);
                        }
                    }

                    PointGroupCollection pointGroups = CivilApplication.ActiveDocument.PointGroups;
                    string groupName = "Group Import " + DateTime.Now.ToString("MM-dd-yy");
                    if (!pointGroups.Contains(groupName))
                    {
                        ObjectId pointGroup           = pointGroups.Add(groupName);
                        StandardPointGroupQuery query = new StandardPointGroupQuery
                        {
                            IncludeNumbers = confirmed
                        };
                        PointGroup group = (PointGroup)pointGroup.GetObject(OpenMode.ForWrite);
                        group.SetQuery(query);
                    }

                    /*foreach (var newPoint in newPoints)
                     * {
                     *  if (points.Where(pn => pn.PointNumber == (uint)newPoint[0]).Count() == 0)
                     *  {
                     *      Point3d point = new Point3d((double)newPoint[2], (double)newPoint[1], (double)newPoint[3]);
                     *      ObjectId pointId = cogoPoints.Add(point, false);
                     *      CogoPoint cogop = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                     *      cogop.PointNumber = (uint)newPoint[0];
                     *      cogop.RawDescription = (string)newPoint[4];
                     *      points.Add(cogop);
                     *  }
                     *  else
                     *  {
                     *      if (points.Where(pn => pn.RawDescription == (string)newPoint[4]).Count() == 0)
                     *      {
                     *          MessageBox.Show("A point with a conflicting point number was detected. You can renumber this.");
                     *      }
                     *      else
                     *      {
                     *          MessageBox.Show("A point with a conflicting point number and description was detected. Ingoring a duplicate point");
                     *      }
                     *  }
                     * }*/
                    object acad = AcApp.AcadApplication;
                    acad.GetType().InvokeMember("ZoomExtents", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, null);
                    trans.Commit();
                }
            }

            Logging.LogEntry(jobNumber, "POINT IMPORT", "Points were added to drawing.");

            form.Dispose();
            ed.Regen();
        }
Exemplo n.º 3
0
        public static void GroupCalcPoints()
        {
            Document      acDoc = AcApp.DocumentManager.MdiActiveDocument;
            Database      acDb  = acDoc.Database;
            Editor        adEd  = acDoc.Editor;
            CivilDocument cApp  = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            List <string> points  = new List <string> {
            };
            string pointStr       = "";
            string descriptionStr = "";

            // Get the purpose of the points
            PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter the purpose: ")
            {
                AllowSpaces = true
            };
            PromptResult pRlt = adEd.GetString(pStrOpts);

            // If the string was empty (or null somehow)
            if (string.IsNullOrEmpty(pRlt.StringResult))
            {
                adEd.WriteMessage("\nThe string entered was empty, please try again."); return;
            }
            string purpose = pRlt.StringResult;

            //Selection method
            PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("\nPlease select a method of point selection: ");

            pKeyOpts.Keywords.Add("List");
            pKeyOpts.Keywords.Add("Selection");
            pKeyOpts.Keywords.Add("Descriptions");
            pKeyOpts.Keywords.Default = "List";
            pKeyOpts.AllowNone        = true;

            pRlt = adEd.GetKeywords(pKeyOpts);
            string selType = pRlt.StringResult;

            switch (selType)
            {
            case "List":
            {
                pStrOpts = new PromptStringOptions("\nEnter the point range using dashes (-) and commas (,): ")
                {
                    AllowSpaces = true
                };
                pRlt = adEd.GetString(pStrOpts);
                if (string.IsNullOrEmpty(pRlt.StringResult))
                {
                    adEd.WriteMessage("\nThe string entered was empty, please try again."); return;
                }
                pointStr = pRlt.StringResult;

                break;
            }

            case "Selection":
            {
                TypedValue[] tvs = new TypedValue[]
                {
                    new TypedValue((int)DxfCode.Start, "AECC_COGO_POINT")
                };
                SelectionFilter       selFltr = new SelectionFilter(tvs);
                PromptSelectionResult acSSPrompt;
                acSSPrompt = adEd.GetSelection(selFltr);
                if (acSSPrompt.Status == PromptStatus.Cancel)
                {
                    adEd.WriteMessage("\nAction aborted."); return;
                }
                if (acSSPrompt.Value.Count < 1)
                {
                    adEd.WriteMessage("\nThe selectiond was empty, please try again."); return;
                }
                using (Transaction tr = acDb.TransactionManager.StartTransaction())
                {
                    foreach (var obj in acSSPrompt.Value.GetObjectIds())
                    {
                        CogoPoint pnt = (CogoPoint)obj.GetObject(OpenMode.ForRead);
                        points.Add(pnt.PointNumber.ToString());
                    }
                    points.Sort();
                }
                pointStr = BeautifyPointList(points);
                break;
            }

            case "Descriptions":
            {
                pStrOpts = new PromptStringOptions("\nEnter the raw descriptions including wildcards (*) and commas (,): ")
                {
                    AllowSpaces = true
                };
                pRlt = adEd.GetString(pStrOpts);
                if (string.IsNullOrEmpty(pRlt.StringResult))
                {
                    adEd.WriteMessage("\nThe string entered was empty, please try again."); return;
                }
                descriptionStr = pRlt.StringResult;

                break;
            }

            default:
            {
                MessageBox.Show($"The selected input for GroupCalc Command was not valid: {pRlt.StringResult}");
                return;
            }
            }
            if (string.IsNullOrEmpty(pointStr) && string.IsNullOrEmpty(descriptionStr))
            {
                adEd.WriteMessage("\nNo points were detected"); return;
            }
            using (Transaction tr = acDb.TransactionManager.StartTransaction())
            {
                //Establish points
                string groupName = $"[{DateTime.Now:MM-dd-yyyy}] {purpose.ToUpper()}";

                StandardPointGroupQuery query = new StandardPointGroupQuery();
                if (selType == "Descriptions")
                {
                    query.IncludeRawDescriptions = descriptionStr;
                }
                else
                {
                    query.IncludeNumbers = pointStr;
                }

                PointGroupCollection pointGroups = cApp.PointGroups;
                if (pointGroups.Contains(groupName))
                {
                    adEd.WriteMessage("\nThe point group already exists, edit the existing group or come up with another name...");
                    return;
                }
                ObjectId   groupId = pointGroups.Add(groupName);
                PointGroup group   = (PointGroup)groupId.GetObject(OpenMode.ForRead);
                group.SetQuery(query);
                tr.Commit();
            }
            adEd.WriteMessage("\nPoint group created successfully!");
        }