- 积分
- 6437
- 明经币
- 个
- 注册时间
- 2012-3-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
如代码,首先在当前数据库中新建一个文字和圆(新建圆的目的是为了方便查看文字是否为居中对齐),接着在当前文档的一新建数据库中新建一个文字和圆,奇怪的现象就在于:在当前和新建数据库中新建文字的代码是一模一样的,在当前数据库中的新建的文字正如代码一样是正中对齐的,而在新建数据库另存的图形中新建的文字通过查看对象特性发现也是正中对齐,但是实际情况却是文字的position位置在圆心处,而alignmentpoint位置却不在圆心处,双击文字后alignmentpoint位置才变到圆心处。我实在是理解不了,到底为什么会出现这种情况,期待狐版主和各位高手一解疑惑!!!- [CommandMethod("sy")]
- 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[BlockTableRecord.ModelSpace], 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[BlockTableRecord.ModelSpace], 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();
- }
- }
|
|