CAD插入图块前修改图块文字
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// 插入块的块名。 String sBlkName = "MyBlkName"; // 把要插入的块文件引入到控件数据库中。 String sBlkFile = axMxDrawX1.GetOcxAppPath() + "\\Blk\\attribblock.dwg"; axMxDrawX1.InsertBlock(sBlkFile, sBlkName); // 得到当前应用对象 MxDrawApplication app = new MxDrawApplication(); // 取到控件数据库 MxDrawDatabase database = app.WorkingDatabase(); // 得到块表对象 MxDrawBlockTable blkTable = database.GetBlockTable(); // 当前块表中是否已经有名为sBlkName的块表记录 MxDrawBlockTableRecord blkRec = blkTable.GetAt(sBlkName, true); if (blkRec == null) { // 证明InsertBlock函数失败,没有成功把文件插入数据库中。 return; } // 创建一个用于遍历块表遍历器 MxDrawBlockTableRecordIterator iter = blkRec.NewIterator(); if (iter == null) return; for (; !iter.Done(); iter.Step(true, false)) { // 得到遍历器当前的实体 MxDrawEntity ent = iter.GetEntity(); if (ent == null) continue; if (ent.ObjectName == "McDbText") { // 当前实体是一个文字 MxDrawText text = (MxDrawText)ent; // 修改文字内容为 "MyContent" text.TextString = "MyContent"; } } // 创建块引用,把图块插入到当前空间,并显示。 axMxDrawX1.DrawBlockReference(0, 0, sBlkName, 1.0, 0.0); |
浙公网安备 33010602011771号