@atlisp/mcp 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cad-worker.js +49 -1
- package/src/handlers/cad-handlers.js +1 -1
package/package.json
CHANGED
package/src/cad-worker.js
CHANGED
|
@@ -47,6 +47,45 @@ const cadConnect = edge.func(function() {/*
|
|
|
47
47
|
}
|
|
48
48
|
*/});
|
|
49
49
|
|
|
50
|
+
const cadLaunch = edge.func(function() {/*
|
|
51
|
+
async (input) => {
|
|
52
|
+
string[] platforms = { "AutoCAD", "ZWCAD", "GStarCAD", "BricsCAD" };
|
|
53
|
+
string[] progIds = { "AutoCAD.Application", "ZWCAD.Application", "GStarCAD.Application", "BricsCAD.Application" };
|
|
54
|
+
|
|
55
|
+
for (int i = 0; i < platforms.Length; i++) {
|
|
56
|
+
try {
|
|
57
|
+
dynamic cad = System.Runtime.InteropServices.Marshal.GetActiveObject(progIds[i]);
|
|
58
|
+
if (cad != null) {
|
|
59
|
+
string ver = cad.Version.ToString();
|
|
60
|
+
return new { success = true, platform = platforms[i], version = ver, launched = false };
|
|
61
|
+
}
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (int i = 0; i < platforms.Length; i++) {
|
|
66
|
+
try {
|
|
67
|
+
var type = System.Type.GetTypeFromProgID(progIds[i]);
|
|
68
|
+
if (type != null) {
|
|
69
|
+
dynamic cad = System.Activator.CreateInstance(type);
|
|
70
|
+
if (cad != null) {
|
|
71
|
+
for (int retry = 0; retry < 60; retry++) {
|
|
72
|
+
await System.Threading.Tasks.Task.Delay(500);
|
|
73
|
+
try {
|
|
74
|
+
string ver = cad.Version.ToString();
|
|
75
|
+
return new { success = true, platform = platforms[i], version = ver, launched = true };
|
|
76
|
+
} catch {}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (Exception ex) {
|
|
81
|
+
System.Diagnostics.Debug.WriteLine("Create COM " + platforms[i] + " error: " + ex.Message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return new { success = false, error = "No CAD found" };
|
|
86
|
+
}
|
|
87
|
+
*/});
|
|
88
|
+
|
|
50
89
|
const cadSend = edge.func(function() {/*
|
|
51
90
|
async (input) => {
|
|
52
91
|
try {
|
|
@@ -255,8 +294,17 @@ async function handleMessage(msg) {
|
|
|
255
294
|
return { pong: true };
|
|
256
295
|
}
|
|
257
296
|
if (msg.type === 'connect') {
|
|
297
|
+
try {
|
|
298
|
+
const result = await new Promise((resolve, reject) => {
|
|
299
|
+
cadConnect({}, (e, r) => {
|
|
300
|
+
if (e) reject(e);
|
|
301
|
+
else resolve(r);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
if (result && result.success) return result;
|
|
305
|
+
} catch (e) {}
|
|
258
306
|
return new Promise((resolve, reject) => {
|
|
259
|
-
|
|
307
|
+
cadLaunch({}, (e, r) => {
|
|
260
308
|
if (e) reject(e);
|
|
261
309
|
else resolve(r);
|
|
262
310
|
});
|
|
@@ -13,7 +13,7 @@ export async function connectCad() {
|
|
|
13
13
|
} catch (e) {
|
|
14
14
|
log('connect_cad error: ' + e.message);
|
|
15
15
|
}
|
|
16
|
-
return { content: [{ type: 'text', text: '
|
|
16
|
+
return { content: [{ type: 'text', text: '未能连接或启动 CAD,请确保 CAD 已安装' }], isError: true };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export async function evalLisp(code, withResult = false) {
|