Beispiel #1
0
        public static DBObject Create(this Grevit.Types.DrawingPoint a, Transaction tr)
        {
            try
            {
                LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);
                Point3d pp = a.point.ToPoint3d();
                DBPoint ppp = new DBPoint(pp);
                ppp.SetDatabaseDefaults(Command.Database);

                if (a.TypeOrLayer != "") { if (lt.Has(a.TypeOrLayer)) ppp.LayerId = lt[a.TypeOrLayer]; }
                BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                ms.AppendEntity(ppp);
                tr.AddNewlyCreatedDBObject(ppp, true);
                return ppp;
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }


            return null;

        }
Beispiel #2
0
        public void iCmd_ConvertCircleToPoint()
        {
            IList <Circle> circles;

            if (!TrySelectObjects <Circle>(out circles, OpenMode.ForRead, "\nВыберите круги: "))
            {
                return;
            }
            try
            {
                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockTable acBlkTbl;
                    acBlkTbl = trans.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId,
                                               OpenMode.ForRead) as BlockTable;
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                  OpenMode.ForWrite) as BlockTableRecord;
                    foreach (var circle in circles)
                    {
                        DBPoint point = new DBPoint(new Point3d(circle.Center.ToArray()));
                        point.SetDatabaseDefaults();
                        acBlkTblRec.AppendEntity(point);
                        trans.AddNewlyCreatedDBObject(point, true);
                    }
                    trans.Commit();
                }
            }
            catch (Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message); }
        }
        public static ObjectId CreatePoint(this Database database, Point3d p, string layerName = null, short layerColor = 256, short entityCollor = 256)
        {
            using (var transAction = database.TransactionManager.StartOpenCloseTransaction())
            {
                // Get the layer table from the drawing
                using (var blocktable = (BlockTable)transAction.GetObject(database.BlockTableId, OpenMode.ForRead))
                {
                    var blockTableRecord = (BlockTableRecord)transAction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    ObjectId id;
                    //create the entity
                    using (var dbPoint = new DBPoint(p))

                    {
                        dbPoint.SetDatabaseDefaults();

                        if (layerName != null)
                        {
                            database.CreateLayer(layerName, layerColor, "");
                            dbPoint.Layer = layerName;
                        }

                        dbPoint.ColorIndex = entityCollor;
                        id = blockTableRecord.AppendEntity(dbPoint);
                        transAction.AddNewlyCreatedDBObject(dbPoint, true);
                        transAction.Commit();
                        return(id);
                    }
                }
            }
        }
Beispiel #4
0
        public static DBObject Create(this Grevit.Types.DrawingPoint a, Transaction tr)
        {
            try
            {
                LayerTable lt  = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);
                Point3d    pp  = a.point.ToPoint3d();
                DBPoint    ppp = new DBPoint(pp);
                ppp.SetDatabaseDefaults(Command.Database);

                if (a.TypeOrLayer != "")
                {
                    if (lt.Has(a.TypeOrLayer))
                    {
                        ppp.LayerId = lt[a.TypeOrLayer];
                    }
                }
                BlockTable       bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                ms.AppendEntity(ppp);
                tr.AddNewlyCreatedDBObject(ppp, true);
                return(ppp);
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }


            return(null);
        }
Beispiel #5
0
        public static void Create(Grevit.Types.DrawingPoint a)
        {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                Point3d pp = GrevitPtoPoint3d(a.point);
                DBPoint ppp = new DBPoint(pp);
                ppp.SetDatabaseDefaults(db);

                if (a.TypeOrLayer != "") { if (lt.Has(a.TypeOrLayer)) ppp.LayerId = lt[a.TypeOrLayer]; }
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                ms.AppendEntity(ppp);
                tr.AddNewlyCreatedDBObject(ppp, true);
                writeProperties(ppp, a.parameters, tr);
                storeID(a, ppp.Id);
                tr.Commit();
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                ed.WriteMessage(e.Message);
                tr.Abort();
            }

            finally
            {
                tr.Dispose();
            }
        }
Beispiel #6
0
        public void AddPointZ()
        {
            Editor             ed            = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions getStartPoint = new PromptPointOptions("Select start point");
            PromptPointResult  startPoint    = ed.GetPoint(getStartPoint);

            PromptPointOptions getEndtPoint = new PromptPointOptions("Select end point");
            PromptPointResult  endPoint     = ed.GetPoint(getEndtPoint);

            PromptPointOptions getNewPoint = new PromptPointOptions("Select new point");
            PromptPointResult  newPoint    = ed.GetPoint(getNewPoint);

            //Create new point
            Database    curDwg      = Application.DocumentManager.MdiActiveDocument.Database;
            Transaction transaction = curDwg.TransactionManager.StartTransaction();
            BlockTable  blkTbl;

            blkTbl = transaction.GetObject(curDwg.BlockTableId, OpenMode.ForRead) as BlockTable;

            BlockTableRecord blkTblRec;

            blkTblRec = transaction.GetObject(blkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            // Create a point with selected new point
            double xStartPoint = startPoint.Value.X;
            double yStartPoint = startPoint.Value.Y;
            double zStartPoint = startPoint.Value.Z;

            double xEndPoint = endPoint.Value.X;
            double yEndPoint = endPoint.Value.Y;
            double zEndPoint = endPoint.Value.Z;

            double xCreatePoint = newPoint.Value.X;
            double yCreatePoint = newPoint.Value.Y;
            double zCreatePoint;

            double distanceStartEndPoints = Math.Sqrt(Math.Pow((xStartPoint - xEndPoint), 2) + Math.Pow((yStartPoint - yEndPoint), 2));
            double distanceStartNewPoints = Math.Sqrt(Math.Pow((xStartPoint - xCreatePoint), 2) + Math.Pow((yStartPoint - yCreatePoint), 2));

            zCreatePoint = Math.Abs(zStartPoint - zEndPoint) * distanceStartNewPoints / distanceStartEndPoints + zStartPoint;

            //point addition TODO commented START
            DBPoint dbPoint = new DBPoint(new Point3d(xCreatePoint, yCreatePoint, zCreatePoint));

            dbPoint.SetDatabaseDefaults();
            // Add the new object to the block table record and the transaction
            blkTblRec.AppendEntity(dbPoint);
            transaction.AddNewlyCreatedDBObject(dbPoint, true);
            //point addition TODO commented END

            // Save the new object to the database
            transaction.Commit();

#if (DEBUG_PRINT)
            Application.ShowAlertDialog("start point = (" + xStartPoint.ToString() + " ," + yStartPoint.ToString() + " ," + zStartPoint.ToString() + ")");
            Application.ShowAlertDialog("end point = (" + xEndPoint.ToString() + " ," + yEndPoint.ToString() + " ," + zEndPoint.ToString() + ")");
            Application.ShowAlertDialog("distanceStartEndPoints=" + distanceStartEndPoints.ToString() + "; distanceStartNewPoints=" + distanceStartNewPoints.ToString() + ")");
#endif
        }
Beispiel #7
0
        //This function gets the 5 points on the passed arc and adds those points
        //to passed point array (pointList)
        static public void BreakArc(ref Arc arc, ref Point3dCollection pointList)
        {
            CircularArc3d arcseg = new CircularArc3d(arc.Center, arc.Normal, arc.Normal.GetPerpendicularVector(),
                                                     arc.Radius, arc.StartAngle, arc.EndAngle);

            var pointArray = arcseg.GetSamplePoints(5);

            bool bReverse = false;

            //Whether to bReverse the reading of points from line, this case is valid
            //only if this function is called for line segment of polyline.
            if (pointList.Count > 0)
            {
                Point3d currentPoint = pointList[pointList.Count - 1];

                if (currentPoint != pointArray[0].Point)
                {
                    bReverse = true;
                }
            }
            int nLength = pointArray.Length;
            int nIndex  = 0;

            if (bReverse == false)
            {
                while (nIndex < nLength)
                {
                    if (pointList.Contains(pointArray[nIndex].Point) == false)
                    {
                        pointList.Add(pointArray[nIndex].Point);

                        DBPoint point = new DBPoint(pointArray[nIndex].Point);
                        point.ColorIndex = 1;
                        point.SetDatabaseDefaults();
                        TGpoints.Add(point);
                    }
                    nIndex++;
                }
            }
            else
            {
                nIndex = nLength;
                while (nIndex > 0)
                {
                    nIndex = nIndex - 1;
                    if (pointList.Contains(pointArray[nIndex].Point) == false)
                    {
                        pointList.Add(pointArray[nIndex].Point);

                        DBPoint point = new DBPoint(pointArray[nIndex].Point);
                        point.ColorIndex = 1;
                        point.SetDatabaseDefaults();
                        TGpoints.Add(point);
                    }
                }
            }
        }
        /// <summary>
        /// Function for creating point primitive on autocad drawing
        /// </summary>
        /// <param name="x">X coordinate of point</param>
        /// <param name="y">Y coordinate of point</param>
        /// <param name="z">Z coordinate of point</param>
        /// <param name="color">Color of point</param>
        /// <returns></returns>
        static DBPoint CreatePointPrimitive(double x, double y, double z, Color color)
        {
            DBPoint acadPoint = new DBPoint(new Point3d(x, y, z));

            acadPoint.SetDatabaseDefaults();
            acadPoint.Color = color;

            return(acadPoint);
        }
Beispiel #9
0
        public static void CreateACPoint()
        {
            var AcDoc  = AcApp.DocumentManager.MdiActiveDocument;
            var AcEdit = AcDoc.Editor;
            var AcDb   = AcDoc.Database;
            var OSnapZ = Convert.ToBoolean(AcApp.TryGetSystemVariable("OSnapZ"));

            if (OSnapZ)
            {
                var ret = MessageBox.Show("Objects will be placed at elevation 0. Continue?", "OSnapZ is on", MessageBoxButtons.YesNo);
                if (ret == DialogResult.No)
                {
                    AcEdit.WriteMessage("Command exited per user input.");
                    return;
                }
            }

            AcEdit.WriteMessage("\nPlease select a point " + (OSnapZ ? "[2D]: " : "[3D]: "));


            PromptPointOptions pointOptions = new PromptPointOptions("\nPlease select a point: ")
            {
                AllowNone    = true,
                UseBasePoint = false
            };

            bool continueCommand = true;

            while (continueCommand)
            {
                var point = AcEdit.GetPoint(pointOptions);
                if (point.Status == PromptStatus.Cancel)
                {
                    break;
                }
                Point3d endPt = point.Value;
                if (OSnapZ)
                {
                    endPt = new Point3d(endPt.X, endPt.Y, 0);
                }

                using (Transaction tr = AcDb.TransactionManager.StartTransaction())
                {
                    // Open the Block table record for read
                    BlockTable acBlkTbl = tr.GetObject(AcDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    DBPoint          acPoint     = new DBPoint(endPt);
                    acPoint.SetDatabaseDefaults();
                    acBlkTblRec.AppendEntity(acPoint);
                    tr.AddNewlyCreatedDBObject(acPoint, true);
                    tr.Commit();
                }
            }
        }
Beispiel #10
0
        //This function gets the 5 points on the passed line and adds those points
        //to passed point array (pointList)
        static public void BreakLine(ref Line line, ref Point3dCollection pointList)
        {
            LineSegment3d lineseg    = new LineSegment3d(line.StartPoint, line.EndPoint);
            var           pointArray = lineseg.GetSamplePoints(5);

            bool bReverse = false;

            //Whether to bReverse the reading of points from line, this case is valid
            //only if this function is called for line segment of polyline.
            if (pointList.Count > 0)
            {
                Point3d currentPoint = pointList[pointList.Count - 1];

                if (currentPoint != line.StartPoint)
                {
                    bReverse = true;
                }
            }
            int nLength = pointArray.Length;
            int nIndex  = 0;

            if (bReverse == false)
            {
                while (nIndex < nLength)
                {
                    if (pointList.Contains(pointArray[nIndex].Point) == false)
                    {
                        pointList.Add(pointArray[nIndex].Point);

                        DBPoint point = new DBPoint(pointArray[nIndex].Point);
                        point.ColorIndex = 1;
                        point.SetDatabaseDefaults();
                        TGpoints.Add(point);
                    }
                    nIndex++;
                }
            }
            else
            {
                nIndex = nLength;
                while (nIndex > 0)
                {
                    nIndex = nIndex - 1;
                    if (pointList.Contains(pointArray[nIndex].Point) == false)
                    {
                        pointList.Add(pointArray[nIndex].Point);

                        DBPoint point = new DBPoint(pointArray[nIndex].Point);
                        point.ColorIndex = 1;
                        point.SetDatabaseDefaults();
                        TGpoints.Add(point);
                    }
                }
            }
        }
        private void markSinks(Transaction ts, Point3dCollection sinks)
        {
            // now lets mark each endpoint
            BlockTable acBlkTbl = _database.BlockTableId
                                  .GetObject(OpenMode.ForRead) as BlockTable;
            BlockTableRecord acBlkTblRec =
                acBlkTbl[BlockTableRecord.ModelSpace]
                .GetObject(OpenMode.ForWrite) as BlockTableRecord;

            // set the point style
            _document.Database.Pdmode = 35;
            _document.Database.Pdsize = 10;
            foreach (Point3d sink in sinks)
            {
                DBPoint sinkPoint = new DBPoint(sink);
                sinkPoint.Color = Color.FromRgb(0, 255, 255);
                sinkPoint.SetDatabaseDefaults();
                acBlkTblRec.AppendEntity(sinkPoint);
                ts.AddNewlyCreatedDBObject(sinkPoint, true);
            }
        }
        public static IEnumerable <ObjectId> CreatePoints(this Database database, IEnumerable <Point3d> points, string layerName = null, short layerColor = 256, short entityCollor = 256)
        {
            if (points is null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            using (var transAction = database.TransactionManager.StartOpenCloseTransaction())
            {
                // Get the layer table from the drawing
                using (var blocktable = (BlockTable)transAction.GetObject(database.BlockTableId, OpenMode.ForRead))
                {
                    var blockTableRecord = (BlockTableRecord)transAction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    int count            = points.Count();
                    var ids = new ObjectId[count];
                    //create the layer
                    for (int i = 0; i < count; i++)
                    {
                        using (var dbPoint = new DBPoint(points.ElementAt(i)))

                        {
                            dbPoint.SetDatabaseDefaults();

                            if (layerName != null)
                            {
                                database.CreateLayer(layerName, layerColor, "");
                                dbPoint.Layer = layerName;
                            }

                            dbPoint.ColorIndex = entityCollor;
                            ids[i]             = blockTableRecord.AppendEntity(dbPoint);
                            transAction.AddNewlyCreatedDBObject(dbPoint, true);
                        }
                    }
                    transAction.Commit();
                    return(ids);
                }
            }
        }
Beispiel #13
0
        public void ImportSdrData()
        {
            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("ru-RU");
            SdrReader rd = new SdrReader();

            wnd.OpenFileDialog opfWndDia = new wnd.OpenFileDialog();
            opfWndDia.AddExtension = true;
            opfWndDia.Filter       = "Text files (*.txt)|*.txt|Sdr files (*.sdr)|*.sdr|All files (*.*)|*.*";
            opfWndDia.FilterIndex  = 2;
            if (opfWndDia.ShowDialog() == wnd.DialogResult.OK)
            {
                PromptIntegerOptions scaleOpt = new PromptIntegerOptions("\nУкажите маштаб, 1:");
                scaleOpt.UseDefaultValue = true;
                scaleOpt.DefaultValue    = 1000;
                scaleOpt.AllowNegative   = false;
                scaleOpt.AllowZero       = false;
                scaleOpt.AllowNone       = false;
                PromptIntegerResult scaleRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(scaleOpt);
                if (scaleRes.Status != PromptStatus.OK)
                {
                    return;
                }
                double scale = scaleRes.Value / 1000d;

                PromptIntegerOptions digCountOpt = new PromptIntegerOptions("\nЗнаков после запятой");
                digCountOpt.UseDefaultValue = true;
                digCountOpt.DefaultValue    = 2;
                digCountOpt.AllowNegative   = false;
                PromptIntegerResult digCountRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(digCountOpt);
                if (digCountRes.Status != PromptStatus.OK)
                {
                    return;
                }

                string path   = opfWndDia.FileName;
                var    points = rd._SdrCoordParser(path);
                if (points == null)
                {
                    return;
                }
                string lname     = "__SDRP_" + System.IO.Path.GetFileNameWithoutExtension(opfWndDia.SafeFileName);
                string lnameElev = lname + "__Elevations";
                string lnameName = lname + "__Names";
                Layers.LayerTools.CreateHiddenLayer(lname);
                Layers.LayerTools.CreateHiddenLayer(lnameElev);
                Layers.LayerTools.CreateHiddenLayer(lnameName);

                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockTable acBlkTbl;
                    acBlkTbl = trans.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId,
                                               OpenMode.ForRead) as BlockTable;
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                  OpenMode.ForWrite) as BlockTableRecord;

                    foreach (var p in points)
                    {
                        DBPoint acPoint = new DBPoint(new Point3d(p.y, p.x, p.h));
                        acPoint.Layer = lname;
                        acPoint.SetDatabaseDefaults();
                        Group gr = new Group();

                        string format = digCountRes.Value == 0 ? "#0" : ((Func <string>)(() => { format = "#0."; for (int i = 0; i < digCountRes.Value; i++)
                                                                                                 {
                                                                                                     format += "0";
                                                                                                 }
                                                                                                 return(format); })).Invoke();

                        var text = _CreateText(new Point3d(p.y + 2.0 * scale, p.x, 0), Math.Round(p.h, digCountRes.Value, MidpointRounding.AwayFromZero).ToString(format, culture), lnameElev, scale);

                        var nameText = _CreateText(text, p.name, lnameName, scale);

                        acBlkTblRec.AppendEntity(acPoint);
                        trans.AddNewlyCreatedDBObject(acPoint, true);

                        ObjectId elevId = acBlkTblRec.AppendEntity(text);
                        trans.AddNewlyCreatedDBObject(text, true);


                        ObjectId nameId = acBlkTblRec.AppendEntity(nameText);
                        trans.AddNewlyCreatedDBObject(nameText, true);

                        gr.Append(elevId);
                        gr.Append(nameId);
                        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.AddDBObject(gr);

                        trans.AddNewlyCreatedDBObject(gr, true);
                    }
                    Application.DocumentManager.MdiActiveDocument.Database.Pdmode = 32;
                    Application.DocumentManager.MdiActiveDocument.Database.Pdsize = 2 * scale;
                    trans.Commit();
                }
            }
        }
Beispiel #14
0
        public void iCmd_CreateAcadPointsFromBuffer()
        {
            PromptKeywordOptions kwOpt = new PromptKeywordOptions("\nSelect");

            kwOpt.AllowNone = false;
            kwOpt.Keywords.Add("FromText");
            //kwOpt.Keywords.Add("FromExl");
            kwOpt.Keywords.Add("FromAcadText");
            //kwOpt.Keywords.Add("FromAcadMText");

            PromptResult kwRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetKeywords(kwOpt);

            string data = "";

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

            PromptIntegerOptions scaleOpt = new PromptIntegerOptions("\nSpecify the scale, 1: ");

            scaleOpt.UseDefaultValue = true;
            scaleOpt.DefaultValue    = 1000;
            scaleOpt.AllowNegative   = false;
            scaleOpt.AllowZero       = false;
            scaleOpt.AllowNone       = false;
            PromptIntegerResult scaleRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(scaleOpt);

            if (scaleRes.Status != PromptStatus.OK)
            {
                return;
            }
            double scale = scaleRes.Value / 1000d;

            PromptIntegerOptions digCountOpt = new PromptIntegerOptions("\nNumber of decimal places: ");

            digCountOpt.UseDefaultValue = true;
            digCountOpt.DefaultValue    = 2;
            digCountOpt.AllowNegative   = false;
            PromptIntegerResult digCountRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(digCountOpt);

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

            PromptKeywordOptions groupingOpt = new PromptKeywordOptions("\nGroup data? : ");

            groupingOpt.AllowNone = false;
            groupingOpt.Keywords.Add("Yes");
            groupingOpt.Keywords.Add("No");
            groupingOpt.Keywords.Default = "Yes";
            PromptResult groupingRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetKeywords(groupingOpt);

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

            string lname     = "__CLIPP" + "POINTS";
            string lnameElev = lname + "__Elevations";
            string lnameName = lname + "__Names";

            Layers.LayerTools.CreateHiddenLayer(lname);
            Layers.LayerTools.CreateHiddenLayer(lnameElev);
            Layers.LayerTools.CreateHiddenLayer(lnameName);

            switch (kwRes.StringResult)
            {
            case "FromText":
            {
                data = System.Windows.Forms.Clipboard.GetText();
                break;
            }

            /*case "FromExl":
             *  {
             *      var buff = System.Windows.Forms.Clipboard.GetData(System.Windows.Forms.DataFormats.CommaSeparatedValue.ToString());
             *      if (buff is String)
             *          data = (String)buff;
             *      break;
             *  }*/
            case "FromAcadText":
            {
                data  = "\t" + _getDbTextString("\nSelect text", "is't DBText");
                data += "\t" + _getDbTextString("\nSelect text", "is't DBText");
                break;
            }

            default:
                return;
            }

            data = data.Replace(',', '.');
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(data);
            string[] lines = data.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None);
            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            using (Transaction trans = Tools.StartTransaction())
            {
                BlockTable acBlkTbl;
                acBlkTbl = trans.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId,
                                           OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                              OpenMode.ForWrite) as BlockTableRecord;
                int count = lines.Length;
                foreach (string l in lines)
                {
                    string[] coords = l.Split(new char[] { '\t' }, StringSplitOptions.None);
                    try
                    {
                        string   name    = coords[0];
                        double   y       = double.Parse(coords[1], culture);
                        double   x       = double.Parse(coords[2], culture);
                        double   h       = 0d;
                        ObjectId nameId  = ObjectId.Null;
                        ObjectId pointId = ObjectId.Null;
                        ObjectId elevId  = ObjectId.Null;
                        if (coords.Length > 3)
                        {
                            try
                            {
                                h = double.Parse(coords[3], culture);
                            }
                            catch { }
                            if (coords[3].Length > 0)
                            {
                                string f = "#0";
                                if (digCountRes.Value > 0)
                                {
                                    f = (f += ".").PadRight(f.Length + digCountRes.Value, '0');
                                }
                                var text = _CreateText(new Point3d(x + 2d * scale, y, 0d), h.ToString(f), lnameElev, scale);
                                elevId = acBlkTblRec.AppendEntity(text);
                                trans.AddNewlyCreatedDBObject(text, true);
                            }
                        }
                        DBPoint point = new DBPoint(new Point3d(x, y, h));
                        point.SetDatabaseDefaults();
                        point.Layer = lname;
                        pointId     = acBlkTblRec.AppendEntity(point);
                        trans.AddNewlyCreatedDBObject(point, true);

                        if (name.Length > 0)
                        {
                            var text = _CreateText(new Point3d(x + 2d * scale, y + 3.0d * scale, 0d), name, lnameName, scale);
                            nameId = acBlkTblRec.AppendEntity(text);
                            trans.AddNewlyCreatedDBObject(text, true);
                        }

                        if (groupingRes.StringResult == "Yes")
                        {
                            Group gr = new Group();
                            if (!nameId.IsNull)
                            {
                                gr.Append(nameId);
                            }
                            if (!elevId.IsNull)
                            {
                                gr.Append(elevId);
                            }
                            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.AddDBObject(gr);
                            trans.AddNewlyCreatedDBObject(gr, true);
                        }
                    }
                    catch
                    { count -= 1; }
                }
                Application.DocumentManager.MdiActiveDocument.Database.Pdmode = 32;
                Application.DocumentManager.MdiActiveDocument.Database.Pdsize = 2 * scale;
                trans.Commit();
            }
        }
Beispiel #15
0
        public void PointCloudStart()
        {
            LoadPointCloudForm form = new LoadPointCloudForm();

            if (form.ShowDialog() != DialogResult.OK)
            {
                form.Dispose(); return;
            }
            form.Hide();

            // OpenFileDialog dlg = new OpenFileDialog();
            int      count = 0;
            Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
            double   minX = 153592; double maxX = 163655;
            double   minY = 87427; double maxY = 88619;
            double   minZ = -500; double maxZ = 5500;

            string[] strARR = { form.FN1, form.FN2, form.FN3, form.FN4, form.FN5 };
            for (int i = 0; i < 5; i++)
            {
                if (strARR[i].Length > 0)
                {
                    FileStream   aFile = new FileStream(strARR[i], FileMode.Open);
                    StreamReader sr    = new StreamReader(aFile);
                    string       strLine;
                    string[]     strArr;
                    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                    {
                        // Open the Block table for read
                        BlockTable acBlkTbl;
                        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                        // Open the Block table record Model space for write
                        BlockTableRecord acBlkTblRec;
                        acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                        strLine = sr.ReadLine();
                        while (strLine != null)
                        {
                            strArr = strLine.Split(';');
                            double x = Convert.ToDouble(strArr[0]);
                            double y = Convert.ToDouble(strArr[1]);
                            double z = Convert.ToDouble(strArr[2]);

                            if (((x >= minX) && (x <= maxX)) && ((y >= minY) && (y <= maxY)) && ((z >= minZ) && (z <= maxZ)))
                            {
                                if (count == 0)
                                {
                                    DBPoint acPoint = new DBPoint(new Point3d(x, y, z));

                                    acPoint.SetDatabaseDefaults();
                                    acBlkTblRec.AppendEntity(acPoint);
                                    acTrans.AddNewlyCreatedDBObject(acPoint, true);

                                    // Set the style for all point objects in the drawing
                                    acCurDb.Pdmode = 34;
                                    acCurDb.Pdsize = 1;
                                }
                                count++;
                            }
                            if (count == 100)
                            {
                                count = 0;
                            }

                            strLine = sr.ReadLine();
                        }

                        // Save the new object to the database
                        acTrans.Commit();
                    }
                    sr.Close();
                }
            }
        }