问一个关于文字注记的超级奇怪的现象
如代码,首先在当前数据库中新建一个文字和圆(新建圆的目的是为了方便查看文字是否为居中对齐),接着在当前文档的一新建数据库中新建一个文字和圆,奇怪的现象就在于:在当前和新建数据库中新建文字的代码是一模一样的,在当前数据库中的新建的文字正如代码一样是正中对齐的,而在新建数据库另存的图形中新建的文字通过查看对象特性发现也是正中对齐,但是实际情况却是文字的position位置在圆心处,而alignmentpoint位置却不在圆心处,双击文字后alignmentpoint位置才变到圆心处。我实在是理解不了,到底为什么会出现这种情况,期待狐版主和各位高手一解疑惑!!!public static void main2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt, OpenMode.ForWrite);
TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
TextStyleTableRecord ttr;
Point3d pt = new Point3d(531578.098884716, 3560697.73777648, 0);
if (!tt.Has("宋体"))
{
ttr = new TextStyleTableRecord
{
Name = "宋体",
FileName = "宋体",
XScale = 1
};
tt.UpgradeOpen();
tt.Add(ttr);
tr.AddNewlyCreatedDBObject(ttr, true);
}
DBText txt = new DBText();
txt.TextString = "实验";
txt.Height = 2;
txt.TextStyle = tt["宋体"];
txt.HorizontalMode = TextHorizontalMode.TextCenter;
txt.VerticalMode = TextVerticalMode.TextVerticalMid;
txt.AlignmentPoint = pt;
btr.AppendEntity(txt);
tr.AddNewlyCreatedDBObject(txt, true);
Circle c = new Circle();
c.Center = pt;
c.Radius = 5;
btr.AppendEntity(c);
tr.AddNewlyCreatedDBObject(c, true);
Database db1 = new Database();
using (Transaction tr1 = db1.TransactionManager.StartTransaction())
{
TextStyleTable tt1 = (TextStyleTable)tr1.GetObject(db1.TextStyleTableId, OpenMode.ForRead);
TextStyleTableRecord ttr1;
if (!tt1.Has("宋体"))
{
ttr1 = new TextStyleTableRecord
{
Name = "宋体",
FileName = "宋体",
XScale = 1
};
tt1.UpgradeOpen();
tt1.Add(ttr1);
tr1.AddNewlyCreatedDBObject(ttr1, true);
}
BlockTable bt1 = (BlockTable)tr1.GetObject(db1.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr1 = (BlockTableRecord)tr1.GetObject(bt1, OpenMode.ForWrite);
txt = new DBText();
txt.TextString = "实验";
txt.Height = 2;
txt.TextStyle = tt1["宋体"];
txt.HorizontalMode = TextHorizontalMode.TextCenter;
txt.VerticalMode = TextVerticalMode.TextVerticalMid;
txt.Position = pt;
txt.AlignmentPoint = pt;
btr1.AppendEntity(txt);
tr1.AddNewlyCreatedDBObject(txt, true);
c = new Circle();
c.Center = pt;
c.Radius = 5;
btr1.AppendEntity(c);
tr1.AddNewlyCreatedDBObject(c, true);
tr1.Commit();
}
db1.SaveAs("d:\\实验.dwg", DwgVersion.Current);
tr.Commit();
}
} 你把那个 txt.HorizontalMode = TextHorizontalMode.TextCenter;换成txt.HorizontalMode = TextHorizontalMode.TextMid;不就可以了 j15tty 发表于 2015-7-19 21:25 static/image/common/back.gif
你把那个 txt.HorizontalMode = TextHorizontalMode.TextCenter;换成txt.HorizontalMode = TextHorizontalM ...
不行的,这种方法我试了,还是不能注记在中心位置! changyiran 发表于 2015-7-19 22:02 static/image/common/back.gif
不行的,这种方法我试了,还是不能注记在中心位置!
你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧 j15tty 发表于 2015-7-19 22:08 static/image/common/back.gif
你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧
首先谢谢你,我估计是cad2006的bug。我用的是cad2006。以后我也换成2010开发,不用2006了。 j15tty 发表于 2015-7-19 22:08 static/image/common/back.gif
你的代码我测试了,是可以的,我的CAD是2010,你看一下这个图吧
大侠,生成的D盘的“实验.dwg”你打开看没?是注记在圆心位置吗?
页:
[1]