明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 936|回复: 5

[基础] 问一个关于文字注记的超级奇怪的现象

[复制链接]
发表于 2015-7-19 17:21 | 显示全部楼层 |阅读模式
如代码,首先在当前数据库中新建一个文字和圆(新建圆的目的是为了方便查看文字是否为居中对齐),接着在当前文档的一新建数据库中新建一个文字和圆,奇怪的现象就在于:在当前和新建数据库中新建文字的代码是一模一样的,在当前数据库中的新建的文字正如代码一样是正中对齐的,而在新建数据库另存的图形中新建的文字通过查看对象特性发现也是正中对齐,但是实际情况却是文字的position位置在圆心处,而alignmentpoint位置却不在圆心处,双击文字后alignmentpoint位置才变到圆心处。我实在是理解不了,到底为什么会出现这种情况,期待狐版主和各位高手一解疑惑!!!
  1. [CommandMethod("sy")]
  2.         public static void main2()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             using (Transaction tr = db.TransactionManager.StartTransaction())
  7.             {
  8.                 BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
  9.                 BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  10.                 TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
  11.                 TextStyleTableRecord ttr;
  12.                 Point3d pt = new Point3d(531578.098884716, 3560697.73777648, 0);
  13.                 if (!tt.Has("宋体"))
  14.                 {
  15.                     ttr = new TextStyleTableRecord
  16.                     {
  17.                         Name = "宋体",
  18.                         FileName = "宋体",
  19.                         XScale = 1
  20.                     };
  21.                     tt.UpgradeOpen();
  22.                     tt.Add(ttr);
  23.                     tr.AddNewlyCreatedDBObject(ttr, true);
  24.                 }
  25.                 DBText txt = new DBText();
  26.                 txt.TextString = "实验";
  27.                 txt.Height = 2;
  28.                 txt.TextStyle = tt["宋体"];
  29.                 txt.HorizontalMode = TextHorizontalMode.TextCenter;
  30.                 txt.VerticalMode = TextVerticalMode.TextVerticalMid;
  31.                 txt.AlignmentPoint = pt;
  32.                 btr.AppendEntity(txt);
  33.                 tr.AddNewlyCreatedDBObject(txt, true);
  34.                 Circle c = new Circle();
  35.                 c.Center = pt;
  36.                 c.Radius = 5;
  37.                 btr.AppendEntity(c);
  38.                 tr.AddNewlyCreatedDBObject(c, true);
  39.                 Database db1 = new Database();
  40.                 using (Transaction tr1 = db1.TransactionManager.StartTransaction())
  41.                 {
  42.                     TextStyleTable tt1 = (TextStyleTable)tr1.GetObject(db1.TextStyleTableId, OpenMode.ForRead);
  43.                     TextStyleTableRecord ttr1;
  44.                     if (!tt1.Has("宋体"))
  45.                     {
  46.                         ttr1 = new TextStyleTableRecord
  47.                         {
  48.                             Name = "宋体",
  49.                             FileName = "宋体",
  50.                             XScale = 1
  51.                         };
  52.                         tt1.UpgradeOpen();
  53.                         tt1.Add(ttr1);
  54.                         tr1.AddNewlyCreatedDBObject(ttr1, true);
  55.                     }
  56.                     BlockTable bt1 = (BlockTable)tr1.GetObject(db1.BlockTableId, OpenMode.ForRead);
  57.                     BlockTableRecord btr1 = (BlockTableRecord)tr1.GetObject(bt1[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  58.                     txt = new DBText();
  59.                     txt.TextString = "实验";
  60.                     txt.Height = 2;
  61.                     txt.TextStyle = tt1["宋体"];
  62.                     txt.HorizontalMode = TextHorizontalMode.TextCenter;
  63.                     txt.VerticalMode = TextVerticalMode.TextVerticalMid;
  64.                     txt.Position = pt;
  65.                     txt.AlignmentPoint = pt;
  66.                     btr1.AppendEntity(txt);
  67.                     tr1.AddNewlyCreatedDBObject(txt, true);
  68.                     c = new Circle();
  69.                     c.Center = pt;
  70.                     c.Radius = 5;
  71.                     btr1.AppendEntity(c);
  72.                     tr1.AddNewlyCreatedDBObject(c, true);
  73.                     tr1.Commit();
  74.                 }
  75.                 db1.SaveAs("d:\\实验.dwg", DwgVersion.Current);
  76.                 tr.Commit();
  77.             }
  78.         }
发表于 2015-7-19 21:25 | 显示全部楼层
你把那个 txt.HorizontalMode = TextHorizontalMode.TextCenter;换成txt.HorizontalMode = TextHorizontalMode.TextMid;不就可以了
 楼主| 发表于 2015-7-19 22:02 | 显示全部楼层
j15tty 发表于 2015-7-19 21:25
你把那个 txt.HorizontalMode = TextHorizontalMode.TextCenter;换成txt.HorizontalMode = TextHorizontalM ...

不行的,这种方法我试了,还是不能注记在中心位置!
发表于 2015-7-19 22:08 | 显示全部楼层
changyiran 发表于 2015-7-19 22:02
不行的,这种方法我试了,还是不能注记在中心位置!

你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2015-7-19 23:24 | 显示全部楼层
j15tty 发表于 2015-7-19 22:08
你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧

首先谢谢你,我估计是cad2006的bug。我用的是cad2006。以后我也换成2010开发,不用2006了。
 楼主| 发表于 2015-7-20 00:53 | 显示全部楼层
j15tty 发表于 2015-7-19 22:08
你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧

大侠,生成的D盘的“实验.dwg”你打开看没?是注记在圆心位置吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-5 19:40 , Processed in 0.325844 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表