Example #1
0
        public void MakeCoordinate()
        {
            Document          doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database          db  = doc.Database;
            Editor            ed  = doc.Editor;
            PromptPointResult ppr = null;

            ppr = ed.GetPoint("\nSelect start point: ");
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d pt1 = ppr.Value;

            ppr = ed.GetCorner("\nSelect end point: ", pt1);
            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }
            Point3d pt2 = ppr.Value;

            using (TranMan tm = new TranMan(db))
            {
                Entity[] cross = null;
                Point3d  pcur;

                double startX = (double)Math.Min(pt1.X, pt2.X);
                double endX   = (double)Math.Max(pt1.X, pt2.X);
                double startY = (double)Math.Min(pt1.Y, pt2.Y);
                double endY   = (double)Math.Max(pt1.Y, pt2.Y);

                int count = 0;

                for (double n = startX; n <= endX; n += 200)
                {
                    for (double m = startY; m <= endY; m += 200)
                    {
                        pcur  = new Point3d(n, m, 0);
                        cross = DrawCross(pcur, 20);
                        tm.AddNewDBObject(cross[0]);
                        tm.AddNewDBObject(cross[1]);
                        tm.AddNewDBObject(cross[2]);
                        tm.AddNewDBObject(cross[3]);

                        ++count;
                    }
                }

                tm.Commit();
                ed.WriteMessage("\n " + count.ToString() + " points have been drawn.");
            }
        }
Example #2
0
        public void JDImport()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            // Open JD file
            string jdData;

            string[]          jdDataLine;
            WinformOpenDialog od = new WinformOpenDialog();

            if (od.ShowDialog() == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(od.FileName);
                jdData = sr.ReadToEnd();
                sr.Close();
                jdDataLine = jdData.Split(new char[] { '\n' });
            }
            else
            {
                ed.WriteMessage("\nFailed to open JD data file.");
                return;
            }



            using (TranMan tm = new TranMan(db))
            {
                using (Polyline jdPoly = new Polyline())
                {
                    // jdPoly.AddVertexAt(0, new Point2d(2, 4), 0, 0, 0);
                    // jdPoly.AddVertexAt(1, new Point2d(4, 2), 0, 0, 0);
                    // jdPoly.AddVertexAt(2, new Point2d(6, 4), 0, 0, 0);

                    Point2d pcur;
                    for (int i = 0; i < jdDataLine.Length; ++i)
                    {
                        ed.WriteMessage("\n" + jdDataLine[i]);
                        string[] jdPointInfo = jdDataLine[i].Split(new char[] { ',' });
                        if (jdPointInfo.Length < 4)
                        {
                            continue;
                        }
                        pcur = new Point2d(double.Parse(jdPointInfo[3]), double.Parse(jdPointInfo[2]));
                        jdPoly.AddVertexAt(i, pcur, 0, 0, 0);
                    }

                    tm.AddNewDBObject(jdPoly);
                }

                tm.Commit();
            }
        }
Example #3
0
        public void zzzb()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            // Open JD file
            string jdData;

            string[]          jdDataLine;
            WinformOpenDialog od = new WinformOpenDialog();

            if (od.ShowDialog() == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(od.FileName);
                jdData = sr.ReadToEnd();
                sr.Close();
                jdDataLine = jdData.Split(new char[] { '\n' });
            }
            else
            {
                ed.WriteMessage("\nFailed to open JD data file.");
                return;
            }



            using (TranMan tm = new TranMan(db))
            {
                Point3d pprv = new Point3d(-1, -1, -1);
                Point3d pcur;
                // Point3d textPos;
                for (int i = 0; i < jdDataLine.Length; ++i)
                {
                    ed.WriteMessage("\n" + jdDataLine[i]);
                    string[] jdPointInfo = jdDataLine[i].Split(new char[] { ',' });
                    if (jdPointInfo.Length < 4)
                    {
                        continue;
                    }

                    pcur = new Point3d(double.Parse(jdPointInfo[3]), double.Parse(jdPointInfo[2]), 0);

                    if (i > 0)
                    {
                        var prvX        = pprv.X;
                        var normalSlope = -1 / ((pcur.Y - pprv.Y) / (pcur.X - pprv.X));
                        var normalB     = pcur.Y - normalSlope * pcur.X;
                        var normaLength = 20;

                        var bX = pcur.X + normaLength / Math.Sqrt(Math.Pow(normalSlope, 2) + 1);
                        var bY = normalSlope * bX + normalB;

                        var isRightSide = !IsLeft(pcur, pprv, bX, bY);
                        if (isRightSide)
                        {
                            bX = 2 * pcur.X - bX;
                            bY = 2 * pcur.Y - bY;
                        }

                        var bPoint = new Point3d(bX, bY, 0);

                        // var normalLine = new Line(pcur, new Point3d(0,0,0));
                        ed.WriteMessage("\n" + pcur.ToString());
                        tm.AddNewDBObject(new Line(pcur, bPoint));

                        var zzText = new DBText();
                        zzText.Position   = pcur;
                        zzText.Height     = 5;
                        zzText.Rotation   = Math.Atan(normalSlope) + (isRightSide ? Math.PI : 0);
                        zzText.TextString = jdPointInfo[0];
                        tm.AddNewDBObject(zzText);
                    }

                    pprv = pcur;

                    // tm.AddNewDBObject(new Line(pcur, new Point3d(0,0,0)));
                }

                // tm.AddNewDBObject(null); // TODO: xxx

                tm.Commit();
            }
        }