Пример #1
0
        /// <summary>
        /// Trả về một Rectangle bao quanh một chuỗi
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static Rectangle GetTextBounds(DBText s, double bufer = 0.35)
        {
            Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            byte        n;
            Transaction tr = GLOBAL.CurrentDatabase.TransactionManager.StartTransaction();

            try
            {
                using (tr)
                {
                    BlockTableRecord btr            = (BlockTableRecord)tr.GetObject(GLOBAL.CurrentDatabase.CurrentSpaceId, OpenMode.ForWrite);
                    string           text           = s.TextString;
                    TextStyleTable   textStyleTable = tr.GetObject
                                                      (
                        GLOBAL.CurrentDatabase.TextStyleTableId,
                        OpenMode.ForRead
                                                      ) as TextStyleTable;

                    string currentTextStyle = Application.GetSystemVariable("TEXTSTYLE").ToString();

                    ObjectId textStyleId = ObjectId.Null;
                    textStyleId = textStyleTable[currentTextStyle];
                    Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle
                        = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                    // get textstyle of newly created text
                    TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    // copy properties from TextStyleTableRecord and dbtext to temp AcGi.TextStyle (just very limited one for the future calculation)
                    style.FileName = txtbtr.FileName;
                    // then copy properties from existing text
                    style.TextSize       = s.Height; // txtbtr.TextSize;
                    style.ObliquingAngle = s.Oblique;
                    style.XScale         = s.WidthFactor;
                    // load temp style record
                    try
                    {
                        n = style.LoadStyleRec;
                    }
                    catch { return(null); }

                    Point2d textPos = new Point2d(s.Position.X, s.Position.Y);
                    //bufer = s.Height * 0.35;
                    Point2d p = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(textStyleId, s.TextString, s.Height);

                    Rectangle rec2 = new Rectangle(p.X, p.Y);
                    rec2.LowerLeft  = new Point2d(textPos.X - bufer, textPos.Y - bufer);
                    rec2.UpperLeft  = new Point2d(rec2.LowerLeft.X, rec2.LowerLeft.Y + rec2.Height + 2 * bufer);
                    rec2.UpperRight = new Point2d(rec2.UpperLeft.X + rec2.Width + 2 * bufer, rec2.UpperLeft.Y);
                    rec2.LowerRight = new Point2d(rec2.UpperRight.X, rec2.LowerLeft.Y);

                    return(rec2);
                }
            }
            catch (System.Exception exc)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace);
                return(null);
            }
            finally { }
        }
            public DrawMiddleJackPanelJig(Entity Container, double Scale)
            {
                MyScale = Scale;
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

                ContainerEntity = Container;
                _style          = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
                _style.Font     = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("Calibri", false, true, 0, 0);
                _style.TextSize = 10;
            }
Пример #3
0
            public DrawMeasuredJackPanelJig(double Scale)
            {
                MyScale = Scale;

                // SET TEXT STYLE

                _style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                _style.Font = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("Calibri", false, true, 0, 0);

                _style.TextSize = 10;

                // END OF SET TEXT STYLE

                //AddRegAppTableRecord(RegAppName);


                //Add Consol
            }
Пример #4
0
        /// <summary>
        /// Trả về một Rectangle bao quanh một chuỗi
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static RectangleEx GetTextBounds(DBText s, double bufer = 0.1)
        {
            //bufer *= s.Height;

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            byte n;

            Transaction tr = db.TransactionManager.StartTransaction();

            try
            {
                using (tr)
                {
                    BlockTableRecord btr            = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    string           text           = s.TextString;
                    TextStyleTable   textStyleTable = tr.GetObject
                                                      (
                        db.TextStyleTableId,
                        OpenMode.ForRead
                                                      ) as TextStyleTable;

                    string currentTextStyle = Application.GetSystemVariable("TEXTSTYLE").ToString();

                    ObjectId textStyleId = ObjectId.Null;
                    textStyleId = textStyleTable[currentTextStyle];
                    Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle
                        = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                    // get textstyle of newly created text
                    TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    // copy properties from TextStyleTableRecord and dbtext to temp AcGi.TextStyle (just very limited one for the future calculation)
                    style.FileName = txtbtr.FileName;
                    // then copy properties from existing text
                    style.TextSize       = s.Height; // txtbtr.TextSize;
                    style.ObliquingAngle = s.Oblique;
                    style.XScale         = s.WidthFactor;
                    // load temp style record
                    try
                    {
                        n = style.LoadStyleRec;
                    }
                    catch { return(null); }// something wrong then exit on error

                    // find out the extents
                    Point2d minpt, maxpt;
                    // get extends of text
                    Extents2d ex = style.ExtentsBox(text, true, true, null);

                    minpt = ex.MinPoint;
                    maxpt = ex.MaxPoint;



                    tr.Commit();
                    RectangleEx rec = new RectangleEx(Math.Abs(minpt.X - maxpt.X),
                                                      Math.Abs(minpt.Y - maxpt.Y));

                    Point2d textPos = new Point2d(s.Position.X, s.Position.Y);
                    bufer = s.Height * 0.3;

                    rec.LowerLeft  = new Point2d(textPos.X - bufer, textPos.Y - bufer);
                    rec.UpperLeft  = new Point2d(rec.LowerLeft.X, rec.LowerLeft.Y + rec.Height + 2 * bufer);
                    rec.UpperRight = new Point2d(rec.UpperLeft.X + rec.Width + 2 * bufer, rec.UpperLeft.Y);
                    rec.LowerRight = new Point2d(rec.UpperRight.X, rec.LowerLeft.Y);

                    return(rec);
                }
            }
            catch (System.Exception exc)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace);
                return(null);
            }
            finally { }
        }