管理员
性别: 男
积分:397 阅读权限:144
帖子: 60
加入时间: 2011/9/1
最后登录: 2024/4/26
|
04 | [CommandMethod( "tcenter" )] |
05 | public static void textToCenter() |
07 | Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
08 | Database db = doc.Database; |
09 | Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle(); |
12 | Transaction tr = db.TransactionManager.StartTransaction(); |
17 | BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); |
19 | string text = "1234567890" ; |
21 | DBText txt = new DBText(); |
22 | txt.SetDatabaseDefaults(); |
23 | txt.TextString = text; |
24 | txt.Position = new Point3d(100, 200, 0); |
25 | btr.AppendEntity(txt); |
26 | tr.AddNewlyCreatedDBObject(txt, true ); |
28 | TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(txt.TextStyleId, OpenMode.ForRead); |
30 | style.FileName = txtbtr.FileName; |
32 | style.TextSize = txt.Height; |
33 | style.ObliquingAngle = txt.Oblique; |
34 | style.XScale = txt.WidthFactor; |
38 | n = style.LoadStyleRec; |
43 | Point3d cpt = new Point3d(20, -45, 0); |
48 | Extents2d ex = style.ExtentsBox(text, true , true , null ); |
53 | Point3d newpos = cpt - new Vector3d((minpt.X + maxpt.X) / 2.0, (minpt.Y + maxpt.Y) / 2.0, 0); |
55 | txt.Position = newpos; |
60 | catch (System.Exception exc) |
62 | Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace); |
|