@atlisp/mcp 1.8.18 → 1.8.20
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 +3969 -2535
- package/dist/cad-worker.js +53 -19
- package/dist/config.js +41 -2
- package/dist/handlers/batch-transaction-handlers.js +70 -0
- package/dist/handlers/cad-handlers.js +66 -91
- package/dist/handlers/draw-handlers.js +118 -165
- package/dist/handlers/entity-handlers.js +61 -111
- package/dist/handlers/layer-handlers.js +70 -98
- package/dist/handlers/lint-handlers.js +64 -0
- package/dist/handlers/resource-defs.js +2 -0
- package/dist/handlers/resource-handlers.js +1288 -26
- package/dist/lisp-security.js +0 -17
- package/dist/pipelines/analyze-and-report.json +16 -0
- package/dist/pipelines/batch-export-pdfs.json +11 -0
- package/dist/pipelines/batch-layer-move.json +19 -0
- package/dist/pipelines/export-current-drawing.json +18 -0
- package/dist/pipelines/purge-and-save.json +16 -0
- package/dist/prompts/definitions/analyze-drawing.json +6 -0
- package/dist/prompts/definitions/batch-draw-lines.json +14 -0
- package/dist/prompts/definitions/coding-conventions.json +11 -0
- package/dist/prompts/definitions/color-convert.json +30 -0
- package/dist/prompts/definitions/curve-analysis.json +26 -0
- package/dist/prompts/definitions/excel-report.json +9 -0
- package/dist/prompts/definitions/export-entities.json +17 -0
- package/dist/prompts/definitions/generate-dimension.json +8 -0
- package/dist/prompts/definitions/geometry-calc.json +9 -0
- package/dist/prompts/definitions/json-exchange.json +22 -0
- package/dist/prompts/definitions/manage-blocks.json +28 -0
- package/dist/prompts/definitions/manage-layers.json +35 -0
- package/dist/prompts/definitions/pickset-filter.json +31 -0
- package/dist/prompts/definitions/string-process.json +40 -0
- package/dist/prompts/definitions/test-autolisp.json +33 -0
- package/dist/prompts/definitions/text-process.json +26 -0
- package/dist/prompts/definitions/workflow-3d-model.json +24 -0
- package/dist/prompts/definitions/workflow-batch-operations.json +24 -0
- package/dist/prompts/definitions/workflow-block-manage.json +32 -0
- package/dist/prompts/definitions/workflow-drawing-export.json +23 -0
- package/dist/prompts/definitions/workflow-entity-analysis.json +23 -0
- package/dist/prompts/definitions/workflow-layer-management.json +38 -0
- package/dist/prompts/definitions/workflow-plot-publish.json +28 -0
- package/dist/prompts/definitions/workflow-sheetset.json +29 -0
- package/dist/prompts/definitions/workflow-text-process.json +29 -0
- package/dist/prompts/definitions/workflow-xref-manage.json +28 -0
- package/package.json +7 -3
|
@@ -1,175 +1,128 @@
|
|
|
1
1
|
import { cad } from '../cad.js';
|
|
2
|
-
import { escapeLispString } from '../handler-utils.js';
|
|
3
|
-
|
|
4
|
-
export async
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function drawArc(params) {
|
|
29
|
-
if (!cad.connected) { await cad.connect(); }
|
|
30
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
31
|
-
try {
|
|
32
|
-
const code = `(progn
|
|
33
|
-
(setq cen (list ${params.center}))
|
|
34
|
-
(setq r ${params.radius})
|
|
35
|
-
(setq ang1 (* pi (/ ${params.startAngle} 180.0)))
|
|
36
|
-
(setq ang2 (* pi (/ ${params.endAngle} 180.0)))
|
|
2
|
+
import { withCadConnection, mcpSuccess, escapeLispString } from '../handler-utils.js';
|
|
3
|
+
|
|
4
|
+
export const drawLine = withCadConnection(async (p1, p2) => {
|
|
5
|
+
await cad.sendCommand(`(command "_.LINE" "${escapeLispString(p1)}" "${escapeLispString(p2)}" "")`);
|
|
6
|
+
return mcpSuccess(`已绘制直线: ${p1} → ${p2}`);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const drawCircle = withCadConnection(async (center, radius) => {
|
|
10
|
+
await cad.sendCommand(`(command "_.CIRCLE" "${escapeLispString(center)}" ${radius})`);
|
|
11
|
+
return mcpSuccess(`已绘制圆: 圆心 ${center},半径 ${radius}`);
|
|
12
|
+
});
|
|
13
|
+
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async
|
|
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
|
-
export async function drawMtext(params) {
|
|
96
|
-
if (!cad.connected) { await cad.connect(); }
|
|
97
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
98
|
-
try {
|
|
99
|
-
const w = params.width || 0;
|
|
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
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function drawPolyline(params) {
|
|
109
|
-
if (!cad.connected) { await cad.connect(); }
|
|
110
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
111
|
-
try {
|
|
112
|
-
const pts = params.points.split(/\s+/).filter(Boolean);
|
|
113
|
-
const pointArgs = pts.map(p => `"${escapeLispString(p)}"`).join(' ');
|
|
114
|
-
const closeArg = params.closed ? ' "C"' : ' ""';
|
|
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
|
-
}
|
|
122
|
-
|
|
123
|
-
export async function drawSpline(params) {
|
|
124
|
-
if (!cad.connected) { await cad.connect(); }
|
|
125
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
126
|
-
try {
|
|
127
|
-
const pts = params.points.split(/\s+/).filter(Boolean);
|
|
128
|
-
const pointArgs = pts.map(p => `"${escapeLispString(p)}"`).join(' ');
|
|
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
|
-
}
|
|
136
|
-
|
|
137
|
-
export async function drawPoint(params) {
|
|
138
|
-
if (!cad.connected) { await cad.connect(); }
|
|
139
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
140
|
-
try {
|
|
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
|
-
}
|
|
148
|
-
|
|
149
|
-
export async function drawHatch(params) {
|
|
150
|
-
if (!cad.connected) { await cad.connect(); }
|
|
151
|
-
if (!cad.connected) return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
|
|
152
|
-
try {
|
|
153
|
-
const pattern = params.pattern || 'ANSI31';
|
|
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
|
|
22
|
+
await cad.sendCommand(code);
|
|
23
|
+
return mcpSuccess(`已绘制圆弧: 圆心 ${center},半径 ${radius},角度 ${startAngle}°→${endAngle}°`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const drawRectangle = withCadConnection(async (corner1, corner2) => {
|
|
27
|
+
await cad.sendCommand(`(command "_.RECTANG" "${escapeLispString(corner1)}" "${escapeLispString(corner2)}")`);
|
|
28
|
+
return mcpSuccess(`已绘制矩形: ${corner1} — ${corner2}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
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
|
+
});
|
|
35
|
+
|
|
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
|
+
});
|
|
40
|
+
|
|
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
|
+
});
|
|
46
|
+
|
|
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
|
+
});
|
|
52
|
+
|
|
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
|
+
});
|
|
60
|
+
|
|
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
|
+
});
|
|
67
|
+
|
|
68
|
+
export const drawPoint = withCadConnection(async (point) => {
|
|
69
|
+
await cad.sendCommand(`(command "_.POINT" "${escapeLispString(point)}")`);
|
|
70
|
+
return mcpSuccess(`已创建点: ${point}`);
|
|
71
|
+
});
|
|
72
|
+
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
84
|
+
await cad.sendCommand(boundaryCode);
|
|
85
|
+
await cad.sendCommand(`(command "_.HATCH" "${escapeLispString(pat)}" "" "")`);
|
|
86
|
+
return mcpSuccess(`已创建图案填充: ${pat}`);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const drawHelix = withCadConnection(async (center, topRadius, bottomRadius, height, turns = 3) => {
|
|
90
|
+
await cad.sendCommand(`(command "_.HELIX" "${escapeLispString(center)}" ${bottomRadius} ${topRadius} ${height} ${turns})`);
|
|
91
|
+
return mcpSuccess(`已创建螺旋: 中心 ${center},半径 ${bottomRadius}→${topRadius},高度 ${height},${turns} 圈`);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const drawDonut = withCadConnection(async (center, innerRadius, outerRadius) => {
|
|
95
|
+
await cad.sendCommand(`(command "_.DONUT" ${innerRadius} ${outerRadius} "${escapeLispString(center)}" "")`);
|
|
96
|
+
return mcpSuccess(`已绘制圆环: 中心 ${center},内径 ${innerRadius},外径 ${outerRadius}`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const draw2dSolid = withCadConnection(async (p1, p2, p3, p4) => {
|
|
100
|
+
await cad.sendCommand(`(command "_.SOLID" "${escapeLispString(p1)}" "${escapeLispString(p2)}" "${escapeLispString(p3)}" "${escapeLispString(p4)}" "")`);
|
|
101
|
+
return mcpSuccess(`已创建 2D 实体: ${p1} ${p2} ${p3} ${p4}`);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const drawXline = withCadConnection(async (point, direction) => {
|
|
105
|
+
await cad.sendCommand(`(command "_.XLINE" "${escapeLispString(point)}" "${escapeLispString(direction)}")`);
|
|
106
|
+
return mcpSuccess(`已创建构造线: 经过 ${point},方向 ${direction}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export const drawRay = withCadConnection(async (point, direction) => {
|
|
110
|
+
await cad.sendCommand(`(command "_.RAY" "${escapeLispString(point)}" "${escapeLispString(direction)}")`);
|
|
111
|
+
return mcpSuccess(`已创建射线: 起点 ${point},方向 ${direction}`);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export const drawLeader = withCadConnection(async (points, annotation) => {
|
|
115
|
+
const pts = points.split(/\s+/).filter(Boolean);
|
|
116
|
+
const cmds = pts.map(p => `"${escapeLispString(p)}"`).join(' ');
|
|
117
|
+
if (annotation) {
|
|
118
|
+
await cad.sendCommand(`(command "_.LEADER" ${cmds} "" "${escapeLispString(annotation)}" "")`);
|
|
119
|
+
} else {
|
|
120
|
+
await cad.sendCommand(`(command "_.LEADER" ${cmds} "" "" "")`);
|
|
174
121
|
}
|
|
175
|
-
}
|
|
122
|
+
return mcpSuccess(`已创建引线标注: ${points}`);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const drawTable = withCadConnection(async (insertionPoint, rows, columns, rowHeight = 10, colWidth = 20) => {
|
|
126
|
+
await cad.sendCommand(`(command "_.TABLE" "${escapeLispString(insertionPoint)}" ${columns} ${rows} ${rowHeight} ${colWidth})`);
|
|
127
|
+
return mcpSuccess(`已创建表格: ${insertionPoint},${rows}×${columns}`);
|
|
128
|
+
});
|
|
@@ -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
|
+
});
|