1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace AutoCADFilter
7{
8 public class Filter
9 {
10 public Filter()
11 {
12
13 }
14 /// <summary>
15 /// 读取dwg文件中的文本信息
16 /// </summary>
17 /// <remarks>读取dwg文件中的文本信息</remarks>
18 /// <returns>文本内容</returns>
19 private string ReadDwg(string path)
20 {
21
22 string content = "";
23 string filename = "";
24 FileInfo finfo = new FileInfo(path);
25 filename = finfo.Name;
26 AutoCAD.AcadApplication ap = new AutoCAD.AcadApplication();
27 lock (ap)
28 {
29 try
30 {
31 AutoCAD.AcadDocument ad = ap.Documents.Open(path,true, null);
32 for (int i = 0; i < ad.ModelSpace.Count; i++)
33 {
34 if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbmtext"))
35 {
36 AutoCAD.IAcadMText im = (AutoCAD.IAcadMText)ad.ModelSpace.Item(i);
37 content += im.TextString;
38 }
39 else if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbtext"))
40 {
41 AutoCAD.IAcadText im = (AutoCAD.IAcadText)ad.ModelSpace.Item(i);
42 content += im.TextString;
43 }
44 }
45 ad.Close(false, filename);
46 }
47 finally
48 {
49
50 ap.Quit();
51 }
52 }
53 return content;
54 }
55
56 public string Parse(string path)
57 {
58 return ReadDwg(path);
59
60 }
61 }
62}
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5
6namespace AutoCADFilter
7{
8 public class Filter
9 {
10 public Filter()
11 {
12
13 }
14 /// <summary>
15 /// 读取dwg文件中的文本信息
16 /// </summary>
17 /// <remarks>读取dwg文件中的文本信息</remarks>
18 /// <returns>文本内容</returns>
19 private string ReadDwg(string path)
20 {
21
22 string content = "";
23 string filename = "";
24 FileInfo finfo = new FileInfo(path);
25 filename = finfo.Name;
26 AutoCAD.AcadApplication ap = new AutoCAD.AcadApplication();
27 lock (ap)
28 {
29 try
30 {
31 AutoCAD.AcadDocument ad = ap.Documents.Open(path,true, null);
32 for (int i = 0; i < ad.ModelSpace.Count; i++)
33 {
34 if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbmtext"))
35 {
36 AutoCAD.IAcadMText im = (AutoCAD.IAcadMText)ad.ModelSpace.Item(i);
37 content += im.TextString;
38 }
39 else if (ad.ModelSpace.Item(i).ObjectName.ToLower().Equals("acdbtext"))
40 {
41 AutoCAD.IAcadText im = (AutoCAD.IAcadText)ad.ModelSpace.Item(i);
42 content += im.TextString;
43 }
44 }
45 ad.Close(false, filename);
46 }
47 finally
48 {
49
50 ap.Quit();
51 }
52 }
53 return content;
54 }
55
56 public string Parse(string path)
57 {
58 return ReadDwg(path);
59
60 }
61 }
62}