@atlisp/mcp 1.8.17 → 1.8.19
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/dist/atlisp-mcp.js +2306 -1458
- package/dist/cad-worker.js +53 -17
- package/dist/config.js +13 -2
- package/dist/handlers/batch-transaction-handlers.js +70 -0
- package/dist/handlers/cad-handlers.js +51 -91
- package/dist/handlers/draw-handlers.js +66 -154
- package/dist/handlers/entity-handlers.js +61 -111
- package/dist/handlers/layer-handlers.js +70 -98
- package/dist/handlers/resource-handlers.js +1219 -26
- package/package.json +4 -2
|
@@ -1,175 +1,87 @@
|
|
|
1
1
|
import { cad } from '../cad.js';
|
|
2
|
-
import { escapeLispString } from '../handler-utils.js';
|
|
2
|
+
import { withCadConnection, mcpSuccess, escapeLispString } from '../handler-utils.js';
|
|
3
3
|
|
|
4
|
-
export async
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const code = `(command "_.LINE" "${escapeLispString(params.p1)}" "${escapeLispString(params.p2)}" "")`;
|
|
9
|
-
await cad.sendCommand(code);
|
|
10
|
-
return { content: [{ type: 'text', text: `已绘制直线: ${params.p1} → ${params.p2}` }] };
|
|
11
|
-
} catch (e) {
|
|
12
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
13
|
-
}
|
|
14
|
-
}
|
|
4
|
+
export const drawLine = withCadConnection(async (p1, p2) => {
|
|
5
|
+
await cad.sendCommand(`(command "_.LINE" "${escapeLispString(p1)}" "${escapeLispString(p2)}" "")`);
|
|
6
|
+
return mcpSuccess(`已绘制直线: ${p1} → ${p2}`);
|
|
7
|
+
});
|
|
15
8
|
|
|
16
|
-
export async
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const code = `(command "_.CIRCLE" "${escapeLispString(params.center)}" ${params.radius})`;
|
|
21
|
-
await cad.sendCommand(code);
|
|
22
|
-
return { content: [{ type: 'text', text: `已绘制圆: 圆心 ${params.center},半径 ${params.radius}` }] };
|
|
23
|
-
} catch (e) {
|
|
24
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
9
|
+
export const drawCircle = withCadConnection(async (center, radius) => {
|
|
10
|
+
await cad.sendCommand(`(command "_.CIRCLE" "${escapeLispString(center)}" ${radius})`);
|
|
11
|
+
return mcpSuccess(`已绘制圆: 圆心 ${center},半径 ${radius}`);
|
|
12
|
+
});
|
|
27
13
|
|
|
28
|
-
export async
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(setq
|
|
34
|
-
(setq r ${params.radius})
|
|
35
|
-
(setq ang1 (* pi (/ ${params.startAngle} 180.0)))
|
|
36
|
-
(setq ang2 (* pi (/ ${params.endAngle} 180.0)))
|
|
14
|
+
export const drawArc = withCadConnection(async (center, radius, startAngle, endAngle) => {
|
|
15
|
+
const code = `(progn
|
|
16
|
+
(setq cen (list ${center}))
|
|
17
|
+
(setq r ${radius})
|
|
18
|
+
(setq ang1 (* pi (/ ${startAngle} 180.0)))
|
|
19
|
+
(setq ang2 (* pi (/ ${endAngle} 180.0)))
|
|
37
20
|
(command "_.ARC" "C" cen (polar cen ang1 r) (polar cen ang2 r))
|
|
38
21
|
)`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
22
|
+
await cad.sendCommand(code);
|
|
23
|
+
return mcpSuccess(`已绘制圆弧: 圆心 ${center},半径 ${radius},角度 ${startAngle}°→${endAngle}°`);
|
|
24
|
+
});
|
|
45
25
|
|
|
46
|
-
export async
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const code = `(command "_.RECTANG" "${escapeLispString(params.corner1)}" "${escapeLispString(params.corner2)}")`;
|
|
51
|
-
await cad.sendCommand(code);
|
|
52
|
-
return { content: [{ type: 'text', text: `已绘制矩形: ${params.corner1} — ${params.corner2}` }] };
|
|
53
|
-
} catch (e) {
|
|
54
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
26
|
+
export const drawRectangle = withCadConnection(async (corner1, corner2) => {
|
|
27
|
+
await cad.sendCommand(`(command "_.RECTANG" "${escapeLispString(corner1)}" "${escapeLispString(corner2)}")`);
|
|
28
|
+
return mcpSuccess(`已绘制矩形: ${corner1} — ${corner2}`);
|
|
29
|
+
});
|
|
57
30
|
|
|
58
|
-
export async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const code = `(command "_.POLYGON" ${params.sides} "${escapeLispString(params.center)}" "I" ${params.radius})`;
|
|
63
|
-
await cad.sendCommand(code);
|
|
64
|
-
return { content: [{ type: 'text', text: `已绘制正${params.sides}边形: 中心 ${params.center},半径 ${params.radius}` }] };
|
|
65
|
-
} catch (e) {
|
|
66
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
31
|
+
export const drawPolygon = withCadConnection(async (center, sides, radius) => {
|
|
32
|
+
await cad.sendCommand(`(command "_.POLYGON" ${sides} "${escapeLispString(center)}" "I" ${radius})`);
|
|
33
|
+
return mcpSuccess(`已绘制正${sides}边形: 中心 ${center},半径 ${radius}`);
|
|
34
|
+
});
|
|
69
35
|
|
|
70
|
-
export async
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const code = `(command "_.ELLIPSE" "C" "${escapeLispString(params.center)}" "${escapeLispString(params.majorAxis)}" "${escapeLispString(params.minorAxis)}")`;
|
|
75
|
-
await cad.sendCommand(code);
|
|
76
|
-
return { content: [{ type: 'text', text: `已绘制椭圆: 中心 ${params.center}` }] };
|
|
77
|
-
} catch (e) {
|
|
78
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
36
|
+
export const drawEllipse = withCadConnection(async (center, majorAxis, minorAxis) => {
|
|
37
|
+
await cad.sendCommand(`(command "_.ELLIPSE" "C" "${escapeLispString(center)}" "${escapeLispString(majorAxis)}" "${escapeLispString(minorAxis)}")`);
|
|
38
|
+
return mcpSuccess(`已绘制椭圆: 中心 ${center}`);
|
|
39
|
+
});
|
|
81
40
|
|
|
82
|
-
export async
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const code = `(command "_.TEXT" "${escapeLispString(params.point)}" ${h} "0" "${escapeLispString(params.text)}")`;
|
|
88
|
-
await cad.sendCommand(code);
|
|
89
|
-
return { content: [{ type: 'text', text: `已创建单行文字: "${params.text}"` }] };
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
92
|
-
}
|
|
93
|
-
}
|
|
41
|
+
export const drawText = withCadConnection(async (text, point, height) => {
|
|
42
|
+
const h = height || 2.5;
|
|
43
|
+
await cad.sendCommand(`(command "_.TEXT" "${escapeLispString(point)}" ${h} "0" "${escapeLispString(text)}")`);
|
|
44
|
+
return mcpSuccess(`已创建单行文字: "${text}"`);
|
|
45
|
+
});
|
|
94
46
|
|
|
95
|
-
export async
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const code = `(command "_.MTEXT" "${escapeLispString(params.point)}" "W" ${w} "${escapeLispString(params.text)}" "")`;
|
|
101
|
-
await cad.sendCommand(code);
|
|
102
|
-
return { content: [{ type: 'text', text: `已创建多行文字: "${params.text}"` }] };
|
|
103
|
-
} catch (e) {
|
|
104
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
105
|
-
}
|
|
106
|
-
}
|
|
47
|
+
export const drawMtext = withCadConnection(async (text, point, width) => {
|
|
48
|
+
const w = width || 0;
|
|
49
|
+
await cad.sendCommand(`(command "_.MTEXT" "${escapeLispString(point)}" "W" ${w} "${escapeLispString(text)}" "")`);
|
|
50
|
+
return mcpSuccess(`已创建多行文字: "${text}"`);
|
|
51
|
+
});
|
|
107
52
|
|
|
108
|
-
export async
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const code = `(command "_.PLINE" ${pointArgs}${closeArg})`;
|
|
116
|
-
await cad.sendCommand(code);
|
|
117
|
-
return { content: [{ type: 'text', text: `已创建多段线: ${pts.length} 个顶点` }] };
|
|
118
|
-
} catch (e) {
|
|
119
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
53
|
+
export const drawPolyline = withCadConnection(async (points, closed) => {
|
|
54
|
+
const pts = points.split(/\s+/).filter(Boolean);
|
|
55
|
+
const pointArgs = pts.map(p => `"${escapeLispString(p)}"`).join(' ');
|
|
56
|
+
const closeArg = closed ? ' "C"' : ' ""';
|
|
57
|
+
await cad.sendCommand(`(command "_.PLINE" ${pointArgs}${closeArg})`);
|
|
58
|
+
return mcpSuccess(`已创建多段线: ${pts.length} 个顶点`);
|
|
59
|
+
});
|
|
122
60
|
|
|
123
|
-
export
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const code = `(command "_.SPLINE" ${pointArgs} "" "" "")`;
|
|
130
|
-
await cad.sendCommand(code);
|
|
131
|
-
return { content: [{ type: 'text', text: `已创建样条曲线: ${pts.length} 个控制点` }] };
|
|
132
|
-
} catch (e) {
|
|
133
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
61
|
+
export const drawSpline = withCadConnection(async (points) => {
|
|
62
|
+
const pts = points.split(/\s+/).filter(Boolean);
|
|
63
|
+
const pointArgs = pts.map(p => `"${escapeLispString(p)}"`).join(' ');
|
|
64
|
+
await cad.sendCommand(`(command "_.SPLINE" ${pointArgs} "" "" "")`);
|
|
65
|
+
return mcpSuccess(`已创建样条曲线: ${pts.length} 个控制点`);
|
|
66
|
+
});
|
|
136
67
|
|
|
137
|
-
export
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const code = `(command "_.POINT" "${escapeLispString(params.point)}")`;
|
|
142
|
-
await cad.sendCommand(code);
|
|
143
|
-
return { content: [{ type: 'text', text: `已创建点: ${params.point}` }] };
|
|
144
|
-
} catch (e) {
|
|
145
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
146
|
-
}
|
|
147
|
-
}
|
|
68
|
+
export const drawPoint = withCadConnection(async (point) => {
|
|
69
|
+
await cad.sendCommand(`(command "_.POINT" "${escapeLispString(point)}")`);
|
|
70
|
+
return mcpSuccess(`已创建点: ${point}`);
|
|
71
|
+
});
|
|
148
72
|
|
|
149
|
-
export async
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const pts = params.points.split(/\s+/).filter(Boolean);
|
|
155
|
-
const ptList = pts.map(p => { const [x, y] = p.split(','); return `${x} ${y}`; }).join(' ');
|
|
156
|
-
const lispPts = `(list ${pts.map(p => `(list ${p})`).join(' ')})`;
|
|
157
|
-
const code = `(progn
|
|
73
|
+
export const drawHatch = withCadConnection(async (points, pattern) => {
|
|
74
|
+
const pat = pattern || 'ANSI31';
|
|
75
|
+
const pts = points.split(/\s+/).filter(Boolean);
|
|
76
|
+
const lispPts = `(list ${pts.map(p => `(list ${p})`).join(' ')})`;
|
|
77
|
+
const boundaryCode = `(progn
|
|
158
78
|
(setq pts ${lispPts})
|
|
159
79
|
(entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
|
|
160
80
|
(cons 90 ${pts.length}) '(70 . 1)
|
|
161
81
|
(cons 10 (nth 0 pts)) (cons 10 (nth 1 pts))
|
|
162
82
|
))
|
|
163
83
|
)`;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} catch(hErr) {
|
|
169
|
-
return { content: [{ type: 'text', text: `错误: ${hErr.message}` }], isError: true };
|
|
170
|
-
}
|
|
171
|
-
return { content: [{ type: 'text', text: `已创建图案填充: ${pattern}` }] };
|
|
172
|
-
} catch (e) {
|
|
173
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
84
|
+
await cad.sendCommand(boundaryCode);
|
|
85
|
+
await cad.sendCommand(`(command "_.HATCH" "${escapeLispString(pat)}" "" "")`);
|
|
86
|
+
return mcpSuccess(`已创建图案填充: ${pat}`);
|
|
87
|
+
});
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { cad } from '../cad.js';
|
|
2
|
-
import {
|
|
3
|
-
import { escapeLispString } from '../handler-utils.js';
|
|
4
|
-
|
|
5
|
-
export async function getEntity(handle) {
|
|
6
|
-
if (!cad.connected) { await cad.connect(); }
|
|
7
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
2
|
+
import { withCadConnection, mcpSuccess, mcpError, escapeLispString } from '../handler-utils.js';
|
|
8
3
|
|
|
4
|
+
export const getEntity = withCadConnection(async (handle) => {
|
|
9
5
|
const code = `(progn
|
|
10
6
|
(vl-load-com)
|
|
11
7
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -23,21 +19,14 @@ export async function getEntity(handle) {
|
|
|
23
19
|
nil
|
|
24
20
|
)
|
|
25
21
|
)`;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return { content: [{ type: 'text', text: `未找到实体: ${handle}` }], isError: true };
|
|
30
|
-
}
|
|
31
|
-
return { content: [{ type: 'text', text: result }] };
|
|
32
|
-
} catch (e) {
|
|
33
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
22
|
+
const result = await cad.sendCommandWithResult(code);
|
|
23
|
+
if (!result || result === 'nil') {
|
|
24
|
+
return mcpError(`未找到实体: ${handle}`);
|
|
34
25
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export async function setEntityProperty(handle, property, value) {
|
|
38
|
-
if (!cad.connected) { await cad.connect(); }
|
|
39
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
26
|
+
return mcpSuccess(result);
|
|
27
|
+
});
|
|
40
28
|
|
|
29
|
+
export const setEntityProperty = withCadConnection(async (handle, property, value) => {
|
|
41
30
|
let propCode = '';
|
|
42
31
|
switch (property) {
|
|
43
32
|
case 'layer':
|
|
@@ -53,7 +42,7 @@ export async function setEntityProperty(handle, property, value) {
|
|
|
53
42
|
propCode = `(cons 38 ${isNaN(Number(value)) ? 0 : Number(value)})`;
|
|
54
43
|
break;
|
|
55
44
|
default:
|
|
56
|
-
return
|
|
45
|
+
return mcpError(`不支持的属性: ${property}`);
|
|
57
46
|
}
|
|
58
47
|
|
|
59
48
|
const code = `(progn
|
|
@@ -67,21 +56,14 @@ export async function setEntityProperty(handle, property, value) {
|
|
|
67
56
|
"NOTFOUND"
|
|
68
57
|
)
|
|
69
58
|
)`;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return { content: [{ type: 'text', text: `已设置实体 ${handle} 的 ${property} 为 ${value}` }] };
|
|
74
|
-
}
|
|
75
|
-
return { content: [{ type: 'text', text: `操作失败: ${result}` }], isError: true };
|
|
76
|
-
} catch (e) {
|
|
77
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
59
|
+
const result = await cad.sendCommandWithResult(code);
|
|
60
|
+
if (result === 'OK' || result === '"OK"') {
|
|
61
|
+
return mcpSuccess(`已设置实体 ${handle} 的 ${property} 为 ${value}`);
|
|
78
62
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function deleteEntity(handle) {
|
|
82
|
-
if (!cad.connected) { await cad.connect(); }
|
|
83
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
63
|
+
return mcpError(`操作失败: ${result}`);
|
|
64
|
+
});
|
|
84
65
|
|
|
66
|
+
export const deleteEntity = withCadConnection(async (handle) => {
|
|
85
67
|
const code = `(progn
|
|
86
68
|
(vl-load-com)
|
|
87
69
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -92,21 +74,14 @@ export async function deleteEntity(handle) {
|
|
|
92
74
|
"NOTFOUND"
|
|
93
75
|
)
|
|
94
76
|
)`;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return { content: [{ type: 'text', text: `已删除实体: ${handle}` }] };
|
|
99
|
-
}
|
|
100
|
-
return { content: [{ type: 'text', text: `删除失败: ${result}` }], isError: true };
|
|
101
|
-
} catch (e) {
|
|
102
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
77
|
+
const result = await cad.sendCommandWithResult(code);
|
|
78
|
+
if (result === 'DELETED' || result === '"DELETED"') {
|
|
79
|
+
return mcpSuccess(`已删除实体: ${handle}`);
|
|
103
80
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export async function selectEntities(filter) {
|
|
107
|
-
if (!cad.connected) { await cad.connect(); }
|
|
108
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
81
|
+
return mcpError(`删除失败: ${result}`);
|
|
82
|
+
});
|
|
109
83
|
|
|
84
|
+
export const selectEntities = withCadConnection(async (filter) => {
|
|
110
85
|
let filterCode = 'nil';
|
|
111
86
|
if (filter && (filter.type || filter.layer)) {
|
|
112
87
|
const items = [];
|
|
@@ -128,69 +103,44 @@ export async function selectEntities(filter) {
|
|
|
128
103
|
nil
|
|
129
104
|
)
|
|
130
105
|
)`;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return { content: [{ type: 'text', text: '未找到符合条件的实体' }] };
|
|
135
|
-
}
|
|
136
|
-
return { content: [{ type: 'text', text: result }] };
|
|
137
|
-
} catch (e) {
|
|
138
|
-
return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true };
|
|
106
|
+
const result = await cad.sendCommandWithResult(code);
|
|
107
|
+
if (!result || result === 'nil') {
|
|
108
|
+
return mcpSuccess('未找到符合条件的实体');
|
|
139
109
|
}
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
export
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const result = await cad.sendCommandWithResult('(progn (setq ss (ssget "_X")) (setq handles nil) (setq i 0) (if ss (repeat (sslength ss) (setq handles (cons (cdr (assoc 5 (entget (ssname ss i)))) handles)) (setq i (1+ i)))) (vl-prin1-to-string (reverse handles)))');
|
|
178
|
-
return { content: [{ type: 'text', text: result || '[]' }] };
|
|
179
|
-
} catch (e) { return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true }; }
|
|
180
|
-
}
|
|
181
|
-
export async function selectLast() {
|
|
182
|
-
if (!cad.connected) { await cad.connect(); }
|
|
183
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
184
|
-
try {
|
|
185
|
-
const result = await cad.sendCommandWithResult('(vl-princ-to-string (list (cdr (assoc 5 (entget (entlast))))))');
|
|
186
|
-
return { content: [{ type: 'text', text: result || 'nil' }] };
|
|
187
|
-
} catch (e) { return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true }; }
|
|
188
|
-
}
|
|
189
|
-
export async function selectByColor(colorIndex) {
|
|
190
|
-
if (!cad.connected) { await cad.connect(); }
|
|
191
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
192
|
-
try {
|
|
193
|
-
const result = await cad.sendCommandWithResult(`(progn (setq ss (ssget "_X" (list (cons 62 ${colorIndex})))) (setq handles nil) (setq i 0) (if ss (repeat (sslength ss) (setq handles (cons (cdr (assoc 5 (entget (ssname ss i)))) handles)) (setq i (1+ i)))) (vl-prin1-to-string (reverse handles)))`);
|
|
194
|
-
return { content: [{ type: 'text', text: result || '[]' }] };
|
|
195
|
-
} catch (e) { return { content: [{ type: 'text', text: `错误: ${e.message}` }], isError: true }; }
|
|
196
|
-
}
|
|
110
|
+
return mcpSuccess(result);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export const bringToFrontEntity = withCadConnection(async (handle) => {
|
|
114
|
+
await cad.sendCommand(`(command "_.DRAWORDER" (handent "${escapeLispString(handle)}") "" "_F")\n`);
|
|
115
|
+
return mcpSuccess(`已置于最前: ${handle}`);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const sendToBackEntity = withCadConnection(async (handle) => {
|
|
119
|
+
await cad.sendCommand(`(command "_.DRAWORDER" (handent "${escapeLispString(handle)}") "" "_B")\n`);
|
|
120
|
+
return mcpSuccess(`已置于最后: ${handle}`);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const bringAboveEntity = withCadConnection(async (handle, referenceHandle) => {
|
|
124
|
+
await cad.sendCommand(`(command "_.DRAWORDER" (handent "${escapeLispString(handle)}") "" "_A" (handent "${escapeLispString(referenceHandle)}"))\n`);
|
|
125
|
+
return mcpSuccess(`已置于 ${referenceHandle} 之上`);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export const sendBelowEntity = withCadConnection(async (handle, referenceHandle) => {
|
|
129
|
+
await cad.sendCommand(`(command "_.DRAWORDER" (handent "${escapeLispString(handle)}") "" "_U" (handent "${escapeLispString(referenceHandle)}"))\n`);
|
|
130
|
+
return mcpSuccess(`已置于 ${referenceHandle} 之下`);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export const selectAll = withCadConnection(async () => {
|
|
134
|
+
const result = await cad.sendCommandWithResult('(progn (setq ss (ssget "_X")) (setq handles nil) (setq i 0) (if ss (repeat (sslength ss) (setq handles (cons (cdr (assoc 5 (entget (ssname ss i)))) handles)) (setq i (1+ i)))) (vl-prin1-to-string (reverse handles)))');
|
|
135
|
+
return mcpSuccess(result || '[]');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const selectLast = withCadConnection(async () => {
|
|
139
|
+
const result = await cad.sendCommandWithResult('(vl-princ-to-string (list (cdr (assoc 5 (entget (entlast))))))');
|
|
140
|
+
return mcpSuccess(result || 'nil');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export const selectByColor = withCadConnection(async (colorIndex) => {
|
|
144
|
+
const result = await cad.sendCommandWithResult(`(progn (setq ss (ssget "_X" (list (cons 62 ${colorIndex})))) (setq handles nil) (setq i 0) (if ss (repeat (sslength ss) (setq handles (cons (cdr (assoc 5 (entget (ssname ss i)))) handles)) (setq i (1+ i)))) (vl-prin1-to-string (reverse handles)))`);
|
|
145
|
+
return mcpSuccess(result || '[]');
|
|
146
|
+
});
|