lzx838 发表于 2009-11-16 14:01:00

<p>最好,这么写 new TypedValue(0, "Text,MText") </p><p>NET可以直接使用ObjectDBX,教材嘛.不好说...</p>

518yf 发表于 2009-11-21 21:36:00

我的代码实现功能是:不打开dwg文件,指定查找替换dwg文件中的文字……<br/>foreach (string&nbsp;&nbsp;str in strArry) //strArry存放dwg文件路径的数组<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Database db = new Database(false, true);<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //把源DWG读入辅助数据库<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;db.ReadDwgFile(str.Trim(), FileShare.ReadWrite, true, "");<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //用集合变量来存储块ID的列表<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ObjectIdCollection blockIds = new ObjectIdCollection();<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; TransactionManager tm = db.TransactionManager;<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; using (Transaction myT = tm.StartTransaction())<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//打开块表<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId,OpenMode.ForRead, false);<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//在块表中检查每个块<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; foreach (ObjectId btrId in bt)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Entity ent = tm.GetObject(btrId, OpenMode.ForWrite) as Entity;<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//替换的内容自己写下吧<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (ent is DBText)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 再判断是否有指定文字替换<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; MessageBox.Show("找到指定的文字DBText类型:"+btrId.ToString());<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; MessageBox.Show("什么也没找到:" + btrId.ToString());<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br/><br/>以上代码肯定有错,就是不知道该怎么写,我是cad开发的初学者,主要代码,也是从网上找了好久,才写了一点点,望各位高手指点……

雪山飞狐_lzh 发表于 2009-11-22 17:20:00

<p>BlockTable即块表,保存的是块定义的Id集合,你的代码遍历的是块定义,而不是图元实体</p><p>你应该先打开模型空间,再遍历模型空间获取图元实体</p>

518yf 发表于 2009-11-22 20:24:00

一头雾水,东南西北都分不清……资源又少,又不具体……

雪山飞狐_lzh 发表于 2009-11-22 21:00:00

<p>看下这里吧</p><p><a href="http://www.mjtd.com/helpcenter/netguide/files/WS73099cc142f48755-5c83e7b1120018de8c0-233d.htm">http://www.mjtd.com/helpcenter/netguide/files/WS73099cc142f48755-5c83e7b1120018de8c0-233d.htm</a></p>

518yf 发表于 2009-11-23 08:24:00

谢谢版主了,早看过了,只是E文不好……

whcjg 发表于 2010-10-19 08:51:00

<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">请教大家,我这样打开dwg文件老是报错:Document doc =&nbsp; acadApp.DocumentManager.Open(@"D:\新块.dwg");</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">说执行环境无效</font></p>
<p><font style="BACKGROUND-COLOR: #ffffff" face="Verdana">还说次代码调用另一个函数,当该函数完成后,这是将要执行的下一条语句</font></p>

雪山飞狐_lzh 发表于 2010-10-19 21:48:00

<p>你的完整代码</p>

chpmould 发表于 2010-11-1 22:32:00

哪有好的教材或资料
页: 1 [2]
查看完整版本: [求助]C# 如何打开指定的dwg文件?