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 #2
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());
            }
        }