-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkXref.cs
82 lines (79 loc) · 2.73 KB
/
checkXref.cs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.Runtime;
using System.Windows.Forms;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Autodesk.AutoCAD.DatabaseServices;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
//[assembly: SecuredApplication(
//@"license")]
namespace GetFrameOfRealDwg
{
class MyHostApplicationServices : Autodesk.AutoCAD.DatabaseServices.HostApplicationServices
{
public override System.String FindFile(System.String fileName,
Autodesk.AutoCAD.DatabaseServices.Database database,
Autodesk.AutoCAD.DatabaseServices.FindFileHint hint
)
{
return string.Empty;
}
static public ArrayList GetBlockNames(Database db)
{
ArrayList array = new ArrayList();
Transaction tran = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)tran.GetObject(db.BlockTableId, OpenMode.ForWrite);
foreach (ObjectId recordid in bt)
{
BlockTableRecord record = (BlockTableRecord)tran.GetObject(recordid, OpenMode.ForRead);
if (record.IsFromExternalReference) {
array.Add("\t" + record.Name + "\t" + record.PathName);
}
}
}
catch
{
}
finally
{
}
return array;
}
static int Main(string[] args)
{
MyHostApplicationServices myserver = new MyHostApplicationServices();
int lcid = 0x00001033; // English
int num = 0;
RuntimeSystem.Initialize(myserver, lcid);
for (int i = 0; i < args.Length; i++) {
System.Console.WriteLine(args[i]);
Database Db = new Database(false, true);
Db.ReadDwgFile(args[i], FileShare.Read, false, "");
ArrayList ar = GetBlockNames(Db);
if (ar.Count > 0) {
foreach (string str in ar)
{
System.Console.WriteLine(str);
}
num++;
} else {
System.Console.WriteLine("\t无外部参照");
}
System.Console.WriteLine("");
}
RuntimeSystem.Terminate();
return num;
}
}
}