读取DWG文件中的文本信息(CAD2004)

  还是那句话,工作需要,不然是不会研究这个的.也许有的人会遇到跟我一样的问题,有兴趣看看,可以节约点时间.运行时要引用CAD2004的COM,这种读取文本的方式并不好,需要机器上装有AUTOCAD2004,而且针对不同的版本,程序可能要进行修改,如果有朋友能有比较好的解决方法,或者第三方控件,欢迎联系.下面将代码贴上:
 1 None.gif using  System;
 2 None.gif using  System.Collections.Generic;
 3 None.gif using  System.Text;
 4 None.gif using  System.IO;
 5 None.gif
 6 None.gif namespace  AutoCADFilter
 7 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 8InBlock.gif    public class Filter
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        public Filter()
11ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
12InBlock.gif            
13ExpandedSubBlockEnd.gif        }

14ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
15InBlock.gif        /// 读取dwg文件中的文本信息
16InBlock.gif        /// </summary>
17InBlock.gif        /// <remarks>读取dwg文件中的文本信息</remarks>
18ExpandedSubBlockEnd.gif        /// <returns>文本内容</returns>

19InBlock.gif        private string ReadDwg(string path)
20ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
21InBlock.gif       
22InBlock.gif            string content = "";
23InBlock.gif            string filename = "";
24InBlock.gif            FileInfo finfo = new FileInfo(path);
25InBlock.gif            filename = finfo.Name;
26InBlock.gif            AutoCAD.AcadApplication ap = new AutoCAD.AcadApplication();
27InBlock.gif            lock (ap)
28ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
29InBlock.gif                try
30ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
31InBlock.gif                    AutoCAD.AcadDocument ad = ap.Documents.Open(path,truenull);
32InBlock.gif                    for (int i = 0; i < ad.ModelSpace.Count; i++)
33ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
34InBlock.gif                        if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbmtext"))
35ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
36InBlock.gif                            AutoCAD.IAcadMText im = (AutoCAD.IAcadMText)ad.ModelSpace.Item(i);
37InBlock.gif                            content += im.TextString;
38ExpandedSubBlockEnd.gif                        }

39InBlock.gif                        else if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbtext"))
40ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
41InBlock.gif                            AutoCAD.IAcadText im = (AutoCAD.IAcadText)ad.ModelSpace.Item(i);
42InBlock.gif                            content += im.TextString;
43ExpandedSubBlockEnd.gif                        }

44ExpandedSubBlockEnd.gif                    }

45InBlock.gif                    ad.Close(false, filename);
46ExpandedSubBlockEnd.gif                }

47InBlock.gif                finally
48ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
49InBlock.gif
50InBlock.gif                    ap.Quit();
51ExpandedSubBlockEnd.gif                }

52ExpandedSubBlockEnd.gif            }

53InBlock.gif            return content;
54ExpandedSubBlockEnd.gif        }

55InBlock.gif
56InBlock.gif        public string Parse(string path)
57ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
58InBlock.gif            return ReadDwg(path);
59InBlock.gif          
60ExpandedSubBlockEnd.gif        }

61ExpandedSubBlockEnd.gif    }

62ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/DarkAngel/archive/2007/05/23/readdwg.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值