コード例 #1
0
        public void CDS_CreateCivilDevPoints()
        {
            RandomCoordinateGenerator generator =
                new RandomCoordinateGenerator();
            CogoPointCollection points = _civildoc.CogoPoints;

            Point3dCollection coordinates = generator.GetCoordinates(10);

            points.Add(coordinates, "TREE MAPLE", true, true);

            coordinates = generator.GetCoordinates(10);
            points.Add(coordinates, "WELL DEEP", true, true);
        }
コード例 #2
0
        [CommandMethod("CCPFE_XYZ")] //CCPFE = CreateCogoPointsFromExcel

        static public void CCPFE_XYZ()
        {
            Document      doc  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            CivilDocument Cdoc = CivilApplication.ActiveDocument;
            Editor        ed   = doc.Editor;
            Database      db   = doc.Database;

            double wallThk = 0.3;
            double baseThk = 0.3;

            string[,] data = LoadExcel(getFolderPath());
            for (long i = 1; i < data.GetLength(0); i++)
            {
                double x = Convert.ToDouble(data[i, 4]);
                double y = Convert.ToDouble(data[i, 5]);
                double z = Convert.ToDouble(data[i, 6]);

                CogoPointCollection cogoPoints = Cdoc.CogoPoints;
                ObjectId            pointId    = cogoPoints.Add(new Point3d(x, y, z), true);

                //reverse the angle direction, this input is from 12d
                double rotationAng = -degreeToRad(Convert.ToDouble(data[i, 11]));
                cogoPoints.SetMarkerRotation(pointId, rotationAng);

                //check, this needed to be unique.
                string name = data[i, 2];
                cogoPoints.SetPointName(pointId, name);

                string rawName = data[i, 1];
                cogoPoints.SetRawDescription(pointId, rawName);

                //double scaler = 1.1;
                //cogoPoints.SetScaleXY(pointId, scaler);
            }

            ////start a transaction
            //using (Transaction trans = db.TransactionManager.StartTransaction())
            //{

            //    // All points in a document are held in a CogoPointCollection object
            //    // We can access CogoPointCollection through the CivilDocument.CogoPoints property

            //    CogoPointCollection cogoPoints = CivilApplication.ActiveDocument.CogoPoints;

            //    // Adds a new CogoPoint at the given location with the specified description information
            //    ObjectId pointId = cogoPoints.Add(location, "Survey Point");
            //    CogoPoint cogoPoint = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;

            //    // Set Some Properties
            //    cogoPoint.PointName = "Survey_Base_Point";
            //    cogoPoint.RawDescription = "This is Survey Base Point";

            //    trans.Commit();
            //}
        }
コード例 #3
0
        private ObjectIdCollection createPoints(int numberOfPoints)
        {
            RandomCoordinateGenerator generator =
                new RandomCoordinateGenerator();
            Point3dCollection coordinates =
                generator.GetCoordinates(numberOfPoints);
            CogoPointCollection points = _civildoc.CogoPoints;

            _creationSet++;
            string description = String.Format("Creation {0}", _creationSet);

            return(points.Add(coordinates, description));
        }
コード例 #4
0
        [CommandMethod("gsi")] //Comanda revizuita care importa puncte din fisiere gsi
        public void ImportGSI()
        {
            //Selectia fisierelor gsi
            Document      acadDoc  = Application.DocumentManager.MdiActiveDocument;
            CivilDocument civilDoc = CivilApplication.ActiveDocument;
            Editor        ed       = acadDoc.Editor;
            Database      db       = HostApplicationServices.WorkingDatabase;

            PromptOpenFileOptions POFO = new PromptOpenFileOptions("Select gsi file: ");

            POFO.Filter = ".gsi";

            PromptFileNameResult FileRes = ed.GetFileNameForOpen(POFO);

            if (FileRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nFile selection failed! Aborting.");
                return;
            }
            string cale = FileRes.StringResult;

            PromptResult PSR = ed.GetString("\nSpecify points description");

            if (PSR.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nInvalid description! Aborting.");
                return;
            }
            string descriere = PSR.StringResult;

            String3D listaPuncte = new String3D();

            listaPuncte.ImportGSI(cale);

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                CogoPointCollection cogoPoints = civilDoc.CogoPoints;
                foreach (Punct3D punct in listaPuncte)
                {
                    ObjectId  pointId = cogoPoints.Add(new Point3d(punct.X, punct.Y, punct.Z));
                    CogoPoint cogo    = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                    cogo.RawDescription = descriere;
                }
                trans.Commit();
            }
        }
コード例 #5
0
ファイル: Cogo.cs プロジェクト: dsb6063/TOUR-2018.V18.0
        public static void EditCogoPoints()
        {
            Editor ed = Active.Active.Editor;

            // Select the location for COGO Point

            PromptPointOptions ppo = new PromptPointOptions("\nSelect the location to Create a COGO Point :");

            PromptPointResult ppr = ed.GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }

            Point3d location = ppr.Value;

            //start a transaction

            using (Transaction trans = Active.Active.StartTransaction())
            {
                // All points in a document are held in a CogoPointCollection object

                // We can access CogoPointCollection through the CivilDocument.CogoPoints property

                CogoPointCollection cogoPoints = CivilApplication.ActiveDocument.CogoPoints;

                // Adds a new CogoPoint at the given location with the specified description information

                ObjectId pointId = cogoPoints.Add(location, "Survey Point", true);

                CogoPoint cogoPoint = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;

                // Set Some Properties

                if (cogoPoint != null)
                {
                    cogoPoint.PointName = "Survey_Base_Point";

                    cogoPoint.RawDescription = "This is Survey Base Point";
                }

                trans.Commit();
            }
        }
コード例 #6
0
        [CommandMethod("convacadpts")] //Comanda pentru convertirea punctelor autocad in puncte COGO de civil3d
        public void ConvAcadPts()
        {
            CivilDocument civDoc = CivilApplication.ActiveDocument;
            Database      db     = HostApplicationServices.WorkingDatabase;
            Editor        ed     = Application.DocumentManager.MdiActiveDocument.Editor;

            //Selectia punctelor autocad
            PromptSelectionOptions PrSelOpt = new PromptSelectionOptions();

            PrSelOpt.MessageForAdding  = "\nSelect points to add: ";
            PrSelOpt.MessageForRemoval = "\nSelect points to remove: ";

            TypedValue[]    tvs = { new TypedValue((int)DxfCode.Start, "POINT") };
            SelectionFilter sf  = new SelectionFilter(tvs);

            PromptSelectionResult PrSelRes = ed.GetSelection(PrSelOpt, sf);

            if (PrSelRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nInvalid Selection! Aborting.");
                return;
            }

            //Solicitarea descrierii punctelor COGO
            string descriere = ed.GetString("\nSpecify points description: ").StringResult;

            //Creearea puntelor COGO
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                CogoPointCollection cogoPoints = civDoc.CogoPoints;
                foreach (SelectedObject selObj in PrSelRes.Value)
                {
                    Autodesk.AutoCAD.DatabaseServices.DBPoint punctAcad = (Autodesk.AutoCAD.DatabaseServices.DBPoint)trans.GetObject(selObj.ObjectId, OpenMode.ForRead);
                    ObjectId  pointId = cogoPoints.Add(punctAcad.Position);
                    CogoPoint cogo    = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                    cogo.RawDescription = descriere;
                }
                trans.Commit();
            }
        }
コード例 #7
0
        public void CDS_CreateRandomPoints()
        {
            RandomCoordinateGenerator generator =
                new RandomCoordinateGenerator();
            CogoPointCollection points = _civildoc.CogoPoints;

            // From Point3d
            Point3d  coordinate = generator.GetCoordinate();
            ObjectId pointId    = points.Add(coordinate);

            write("\nSingle Point from coordinate.");
            display(pointId);

            coordinate = generator.GetCoordinate();
            pointId    = points.Add(coordinate, "Sample description.");
            write("\nSingle Point from coordinate and description.");
            display(pointId);

            coordinate = generator.GetCoordinate();
            pointId    = points.Add(coordinate, "Sample description",
                                    true, false);
            write("\nSingle Point from coordinate with description, "
                  + "using description key, and not matching parameters.");
            display(pointId);

            // From Point3dCollection
            Point3dCollection  coordinates = generator.GetCoordinates(10);
            ObjectIdCollection pointIds    = points.Add(coordinates);

            write("\nPoints from coordinate collection.");
            display(pointIds);

            coordinates = generator.GetCoordinates(5);
            pointIds    = points.Add(coordinates, "Group of 5");
            write("\nPoints from coordinate collection with description.");
            display(pointIds);

            coordinates = generator.GetCoordinates(7);
            pointIds    = points.Add(coordinates, "Group of 7", true, true);
            write("\nPoints from coordinate collection with description,"
                  + "using description key, and not matching parameters.");
            display(pointIds);
        }
コード例 #8
0
        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();
        }