Beispiel #1
0
        private void createX(_Db.BlockTableRecord btr, double radius, _Ge.Point3d ip)
        {
            _Ge.Point2d p1 = new _Ge.Point2d(ip.X - radius, ip.Y);
            _Ge.Point2d p2 = new _Ge.Point2d(ip.X + radius, ip.Y);
            _Ge.Point2d p3 = new _Ge.Point2d(ip.X, ip.Y - radius);
            _Ge.Point2d p4 = new _Ge.Point2d(ip.X, ip.Y + radius);

            using (_Db.Polyline poly = new _Db.Polyline())
            {
                poly.AddVertexAt(0, p1, 0, 0, 0);
                poly.AddVertexAt(1, p2, 0, 0, 0);
                poly.ColorIndex = 2;

                btr.AppendEntity(poly);
                _c.trans.AddNewlyCreatedDBObject(poly, true);
            }

            using (_Db.Polyline poly = new _Db.Polyline())
            {
                poly.AddVertexAt(0, p3, 0, 0, 0);
                poly.AddVertexAt(1, p4, 0, 0, 0);
                poly.ColorIndex = 2;

                btr.AppendEntity(poly);
                _c.trans.AddNewlyCreatedDBObject(poly, true);
            }
        }
        public static void BuildingOrthogonalPolylines()
        {
            try
            {
                AcDb.Database db = CurrentCAD.Database;
                jigger = new OrthogonalPolylinesJig();
                AcEd.PromptResult jigRes;
                do
                {
                    jigRes = CurrentCAD.Editor.Drag(jigger);
                    if (jigRes.Status == AcEd.PromptStatus.OK)
                    {
                        jigger.allVertexes.Add(jigger.lastVertex);
                    }
                } while (jigRes.Status == AcEd.PromptStatus.OK);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                    Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline();
                    ent.SetDatabaseDefaults();
                    for (int i = 0; i < jigger.allVertexes.Count; i++)
                    {
                        AcGe.Point3d pt3d = jigger.allVertexes[i];
                        AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y);
                        ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    ent.TransformBy(jigger.UCS);
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CurrentCAD.Editor.WriteMessage(ex.ToString());
            }
        }
Beispiel #3
0
        // Transaction extensions

        ///<summary>
        /// Create a bounding rectangle around a piece of text (for debugging).
        ///</summary>
        ///<param name="txt">The text object around which to create a box.</param>
        public static void CreateBoundingBox(this _AcDb.Transaction tr, _AcDb.DBText txt)
        {
            var ms =
                tr.GetObject(
                    _AcDb.SymbolUtilityServices.GetBlockModelSpaceId(txt.Database),
                    _AcDb.OpenMode.ForWrite

                    ) as _AcDb.BlockTableRecord;

            if (ms != null)
            {
                var corners = txt.ExtractBounds();
                if (corners.Count >= 4)
                {
                    var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
                    if (doc == null)
                    {
                        return;
                    }
                    var ed  = doc.Editor;
                    var ucs = ed.CurrentUserCoordinateSystem;
                    var cs  = ucs.CoordinateSystem3d;
                    var pl  = new _AcDb.Polyline(4);

                    for (int i = 0; i < 4; i++)
                    {
                        pl.AddVertexAt(i, corners[i].ProjectToUcs(cs), 0, 0, 0);
                    }

                    pl.Closed = true;
                    pl.TransformBy(ucs);
                    ms.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                }
            }
        }
Beispiel #4
0
        public static void BuildingRectangle()
        {
            try
            {
                AcDb.Database db = CurrentCAD.Database;
                AcEd.Editor   ed = CurrentCAD.Editor;

                AcEd.PromptKeywordOptions pko;
                AcEd.PromptPointOptions   ppt;
                AcEd.PromptPointResult    ppr;
                AcGe.Point3d basePoint;
                AcGe.Point3d diractionPoint;

                pko = new AcEd.PromptKeywordOptions("\nПобудова прямокутника");

                pko.Keywords.Add("по Діагоналі");
                pko.Keywords.Add("по Напрямку та діагоналі");
                pko.Keywords.Add("по Ширині та висота");
                pko.Keywords.Default = "по Ширині та висота";
                pko.AllowNone        = false;

                AcEd.PromptResult pkr = ed.GetKeywords(pko);

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

                MethodConstructingRectangle methodConstructing;

                if (pkr.StringResult == "Діагоналі")
                {
                    methodConstructing = MethodConstructingRectangle.Diagonal;
                }
                else if (pkr.StringResult == "Напрямку")
                {
                    methodConstructing = MethodConstructingRectangle.DirectionAndDiagonal;
                }
                else
                {
                    methodConstructing = MethodConstructingRectangle.HeightAndWidth;
                }

                ppt = new AcEd.PromptPointOptions("\nВкажіть першу точку прямокутника:");
                ppr = ed.GetPoint(ppt);
                if (ppr.Status != AcEd.PromptStatus.OK)
                {
                    return;
                }

                basePoint = ppr.Value;

                if (methodConstructing == MethodConstructingRectangle.Diagonal)
                {
                    diractionPoint = basePoint.Add(AcGe.Vector3d.XAxis);
                }
                else
                {
                    ppt = new AcEd.PromptPointOptions("\n");
                    if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть точку напрямку прямокутника:";
                    }
                    else if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть ширину прямокутника:";
                    }
                    ppt.UseBasePoint = true;
                    ppt.BasePoint    = basePoint;
                    ppr = ed.GetPoint(ppt);
                    if (ppr.Status != AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    diractionPoint = ppr.Value;
                }
                jigger = new RectangleJig(methodConstructing, basePoint, diractionPoint);
                ed.Drag(jigger);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                    Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline();
                    ent.SetDatabaseDefaults();
                    for (int i = 0; i < jigger.Corners.Count; i++)
                    {
                        AcGe.Point3d pt3d = jigger.Corners[i];
                        AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y);
                        ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    ent.Closed = true;
                    ent.TransformBy(jigger.UCS);
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CurrentCAD.Editor.WriteMessage(ex.ToString());
            }
        }