-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCommandTools.cs
More file actions
167 lines (162 loc) · 5.03 KB
/
Copy pathCommandTools.cs
File metadata and controls
167 lines (162 loc) · 5.03 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace DotNetARX
{
/// <summary>
/// 用于ADSRX库函数(如acedCmd)输入参数的类型
/// </summary>
public enum ResBufCode
{
/// <summary>
/// 用户输入值有效
/// </summary>
Norm = 5100,
/// <summary>
/// 没有结果
/// </summary>
None = 5000,
/// <summary>
/// 实数
/// </summary>
Real = 5001,
/// <summary>
/// 2维点
/// </summary>
Point2d = 5002,
/// <summary>
/// 短整型
/// </summary>
Short = 5003,
/// <summary>
/// 角度
/// </summary>
Angle = 5004,
/// <summary>
/// 字符串
/// </summary>
String = 5005,
/// <summary>
/// 实体Id
/// </summary>
ObjectId = 5006,
/// <summary>
/// 选择集名
/// </summary>
PickSet = 5007,
/// <summary>
/// 方向
/// </summary>
Orientation = 5008,
/// <summary>
/// 三维点
/// </summary>
Point3d = 5009,
/// <summary>
/// 长整数
/// </summary>
Long = 5010,
/// <summary>
/// 空白符号
/// </summary>
Void = 5014,
/// <summary>
/// 列表开始
/// </summary>
ListBegin = 5016,
/// <summary>
/// 列表结束
/// </summary>
ListEnd = 5017,
/// <summary>
/// 点对
/// </summary>
DottedPair = 5018,
/// <summary>
/// 空
/// </summary>
Nil = 5019,
/// <summary>
/// DXF为的0的组码
/// </summary>
DXF0 = 5020,
/// <summary>
/// T atom
/// </summary>
TAtom = 5021,
/// <summary>
/// resbuf
/// </summary>
Resbuf = 5023,
/// <summary>
/// 无模式对话框
/// </summary>
Modeless = 5027,
}
/// <summary>
/// 命令工具类,用来封装COM、C++中的调用AutoCAD命令的函数。
/// </summary>
public static class CommandTools
{
/// <summary>
/// 调用COM的SendCommand函数
/// </summary>
/// <param name="doc">文档对象</param>
/// <param name="args">命令参数列表</param>
public static void SendCommand(this Document doc, params string[] args)
{
Type AcadDocument = Type.GetTypeFromHandle(Type.GetTypeHandle(doc));
try
{
// 通过后期绑定的方式调用SendCommand命令
AcadDocument.InvokeMember("SendCommand", BindingFlags.InvokeMethod, null, doc, args);
}
catch // 捕获异常
{
return;
}
}
[DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acedPostCommand@@YAHPB_W@Z")]
extern static private int acedPostCommand(string strExpr);
/// <summary>
/// 调用C++的acedPostCommand函数
/// </summary>
/// <param name="ed">无意义,只是为了定义扩展函数</param>
/// <param name="expression">要执行的命令字符串</param>
public static void PostCommand(this Editor ed, string expression)
{
acedPostCommand(expression);
}
[DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
extern static private int ads_queueexpr(string strExpr);
/// <summary>
/// 调用C++的ads_queueexpr函数
/// </summary>
/// <param name="ed">无意义,只是为了定义扩展函数</param>
/// <param name="expression">要执行的命令字符串</param>
public static void QueueExpression(this Editor ed, string expression)
{
ads_queueexpr(expression);
}
//调用AutoCAD命令,ARX原型:int acedCmd(const struct resbuf * rbp);
[DllImport("acad.exe", EntryPoint = "acedCmd", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
private extern static int acedCmd(IntPtr rbp);
/// <summary>
/// 调用C++的acedCmd函数
/// </summary>
/// <param name="ed">无意义,只是为了定义扩展函数</param>
/// <param name="args">命令参数列表</param>
/// <returns>返回命令执行的状态</returns>
public static int AcedCmd(this Editor ed, ResultBuffer args)
{
//由于acedCmd只能在程序环境下运行,因此需调用此语句
if (!Application.DocumentManager.IsApplicationContext)
return acedCmd(args.UnmanagedObject);
else
return 0;
}
}
}