solidworks-mcp-server 2.2.0 → 3.0.1
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/README.md +33 -10
- package/dist/application/services/command-bus.d.ts +39 -0
- package/dist/application/services/command-bus.d.ts.map +1 -0
- package/dist/application/services/command-bus.js +88 -0
- package/dist/application/services/command-bus.js.map +1 -0
- package/dist/application/services/event-bus.d.ts +31 -0
- package/dist/application/services/event-bus.d.ts.map +1 -0
- package/dist/application/services/event-bus.js +83 -0
- package/dist/application/services/event-bus.js.map +1 -0
- package/dist/application/services/query-bus.d.ts +30 -0
- package/dist/application/services/query-bus.d.ts.map +1 -0
- package/dist/application/services/query-bus.js +59 -0
- package/dist/application/services/query-bus.js.map +1 -0
- package/dist/application/services/tool-registry.d.ts +53 -0
- package/dist/application/services/tool-registry.d.ts.map +1 -0
- package/dist/application/services/tool-registry.js +81 -0
- package/dist/application/services/tool-registry.js.map +1 -0
- package/dist/application/use-cases/analysis/index.d.ts +13 -0
- package/dist/application/use-cases/analysis/index.d.ts.map +1 -0
- package/dist/application/use-cases/analysis/index.js +17 -0
- package/dist/application/use-cases/analysis/index.js.map +1 -0
- package/dist/application/use-cases/drawing/index.d.ts +13 -0
- package/dist/application/use-cases/drawing/index.d.ts.map +1 -0
- package/dist/application/use-cases/drawing/index.js +17 -0
- package/dist/application/use-cases/drawing/index.js.map +1 -0
- package/dist/application/use-cases/export/index.d.ts +13 -0
- package/dist/application/use-cases/export/index.d.ts.map +1 -0
- package/dist/application/use-cases/export/index.js +17 -0
- package/dist/application/use-cases/export/index.js.map +1 -0
- package/dist/application/use-cases/macro/index.d.ts +13 -0
- package/dist/application/use-cases/macro/index.d.ts.map +1 -0
- package/dist/application/use-cases/macro/index.js +17 -0
- package/dist/application/use-cases/macro/index.js.map +1 -0
- package/dist/application/use-cases/modeling/index.d.ts +56 -0
- package/dist/application/use-cases/modeling/index.d.ts.map +1 -0
- package/dist/application/use-cases/modeling/index.js +385 -0
- package/dist/application/use-cases/modeling/index.js.map +1 -0
- package/dist/core/interfaces/core-abstractions.d.ts +289 -0
- package/dist/core/interfaces/core-abstractions.d.ts.map +1 -0
- package/dist/core/interfaces/core-abstractions.js +121 -0
- package/dist/core/interfaces/core-abstractions.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/index.refactored.d.ts +7 -0
- package/dist/index.refactored.d.ts.map +1 -0
- package/dist/index.refactored.js +254 -0
- package/dist/index.refactored.js.map +1 -0
- package/dist/infrastructure/config/configuration-manager.d.ts +381 -0
- package/dist/infrastructure/config/configuration-manager.d.ts.map +1 -0
- package/dist/infrastructure/config/configuration-manager.js +566 -0
- package/dist/infrastructure/config/configuration-manager.js.map +1 -0
- package/dist/infrastructure/container/service-locator.d.ts +14 -0
- package/dist/infrastructure/container/service-locator.d.ts.map +1 -0
- package/dist/infrastructure/container/service-locator.js +38 -0
- package/dist/infrastructure/container/service-locator.js.map +1 -0
- package/dist/infrastructure/logging/logger.d.ts +24 -0
- package/dist/infrastructure/logging/logger.d.ts.map +1 -0
- package/dist/infrastructure/logging/logger.js +65 -0
- package/dist/infrastructure/logging/logger.js.map +1 -0
- package/dist/infrastructure/solidworks/solidworks-adapter.d.ts +43 -0
- package/dist/infrastructure/solidworks/solidworks-adapter.d.ts.map +1 -0
- package/dist/infrastructure/solidworks/solidworks-adapter.js +527 -0
- package/dist/infrastructure/solidworks/solidworks-adapter.js.map +1 -0
- package/dist/presentation/mcp/request-handler.d.ts +41 -0
- package/dist/presentation/mcp/request-handler.d.ts.map +1 -0
- package/dist/presentation/mcp/request-handler.js +100 -0
- package/dist/presentation/mcp/request-handler.js.map +1 -0
- package/dist/presentation/transformers/error-transformer.d.ts +16 -0
- package/dist/presentation/transformers/error-transformer.d.ts.map +1 -0
- package/dist/presentation/transformers/error-transformer.js +44 -0
- package/dist/presentation/transformers/error-transformer.js.map +1 -0
- package/dist/presentation/transformers/response-transformer.d.ts +24 -0
- package/dist/presentation/transformers/response-transformer.d.ts.map +1 -0
- package/dist/presentation/transformers/response-transformer.js +102 -0
- package/dist/presentation/transformers/response-transformer.js.map +1 -0
- package/dist/shared/constants/solidworks-constants.d.ts +302 -0
- package/dist/shared/constants/solidworks-constants.d.ts.map +1 -0
- package/dist/shared/constants/solidworks-constants.js +471 -0
- package/dist/shared/constants/solidworks-constants.js.map +1 -0
- package/dist/tools/diagnostics.d.ts +21 -0
- package/dist/tools/diagnostics.d.ts.map +1 -0
- package/dist/tools/diagnostics.js +120 -0
- package/dist/tools/diagnostics.js.map +1 -0
- package/dist/tools/drawing-analysis.d.ts +9 -0
- package/dist/tools/drawing-analysis.d.ts.map +1 -0
- package/dist/tools/drawing-analysis.js +239 -0
- package/dist/tools/drawing-analysis.js.map +1 -0
- package/dist/tools/enhanced-drawing.d.ts +51 -0
- package/dist/tools/enhanced-drawing.d.ts.map +1 -0
- package/dist/tools/enhanced-drawing.js +193 -0
- package/dist/tools/enhanced-drawing.js.map +1 -0
- package/dist/tools/macro-security.d.ts +9 -0
- package/dist/tools/macro-security.d.ts.map +1 -0
- package/dist/tools/macro-security.js +86 -0
- package/dist/tools/macro-security.js.map +1 -0
- package/dist/tools/native-macro.d.ts +149 -0
- package/dist/tools/native-macro.d.ts.map +1 -0
- package/dist/tools/native-macro.js +654 -0
- package/dist/tools/native-macro.js.map +1 -0
- package/dist/tools/sketch.d.ts +663 -0
- package/dist/tools/sketch.d.ts.map +1 -0
- package/dist/tools/sketch.js +815 -0
- package/dist/tools/sketch.js.map +1 -0
- package/dist/tools/template-manager.d.ts +231 -0
- package/dist/tools/template-manager.d.ts.map +1 -0
- package/dist/tools/template-manager.js +626 -0
- package/dist/tools/template-manager.js.map +1 -0
- package/package.json +12 -7
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Manager for SolidWorks
|
|
3
|
+
* Comprehensive drawing sheet format and template management
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Template management tools for extracting and applying drawing formats
|
|
8
|
+
*/
|
|
9
|
+
export const templateManagerTools = [
|
|
10
|
+
// ============================================
|
|
11
|
+
// TEMPLATE EXTRACTION
|
|
12
|
+
// ============================================
|
|
13
|
+
{
|
|
14
|
+
name: 'extract_drawing_template',
|
|
15
|
+
description: 'Extract complete template settings from a parent drawing file',
|
|
16
|
+
inputSchema: z.object({
|
|
17
|
+
filePath: z.string().describe('Path to the parent drawing file'),
|
|
18
|
+
includeFormat: z.boolean().default(true).describe('Include sheet format'),
|
|
19
|
+
includeProperties: z.boolean().default(true).describe('Include custom properties'),
|
|
20
|
+
includeStyles: z.boolean().default(true).describe('Include dimension/annotation styles'),
|
|
21
|
+
includeViews: z.boolean().default(false).describe('Include view layout information'),
|
|
22
|
+
saveAs: z.string().optional().describe('Path to save template configuration')
|
|
23
|
+
}),
|
|
24
|
+
handler: (args, swApi) => {
|
|
25
|
+
try {
|
|
26
|
+
swApi.openModel(args.filePath);
|
|
27
|
+
const model = swApi.getCurrentModel();
|
|
28
|
+
if (!model || model.GetType() !== 3) { // 3 = Drawing
|
|
29
|
+
throw new Error('File is not a drawing document');
|
|
30
|
+
}
|
|
31
|
+
const drawing = model;
|
|
32
|
+
const sheet = drawing.GetCurrentSheet();
|
|
33
|
+
const templateData = {
|
|
34
|
+
source: args.filePath,
|
|
35
|
+
extractedAt: new Date().toISOString(),
|
|
36
|
+
sheetFormat: {},
|
|
37
|
+
properties: {},
|
|
38
|
+
styles: {},
|
|
39
|
+
views: []
|
|
40
|
+
};
|
|
41
|
+
// Extract sheet format
|
|
42
|
+
if (args.includeFormat) {
|
|
43
|
+
const format = sheet.GetSheetFormat();
|
|
44
|
+
if (format) {
|
|
45
|
+
templateData.sheetFormat = {
|
|
46
|
+
name: sheet.GetName(),
|
|
47
|
+
size: sheet.GetSize(),
|
|
48
|
+
scale: sheet.GetProperties(),
|
|
49
|
+
orientation: sheet.GetOrientation(),
|
|
50
|
+
firstAngle: sheet.GetFirstAngle(),
|
|
51
|
+
projection: sheet.GetProjection(),
|
|
52
|
+
templatePath: sheet.GetTemplateName(),
|
|
53
|
+
zones: {
|
|
54
|
+
horizontal: sheet.GetZoneHorizontalCount(),
|
|
55
|
+
vertical: sheet.GetZoneVerticalCount()
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Extract custom properties
|
|
61
|
+
if (args.includeProperties) {
|
|
62
|
+
const propMgr = drawing.Extension.CustomPropertyManager("");
|
|
63
|
+
const propNames = propMgr.GetNames();
|
|
64
|
+
if (propNames) {
|
|
65
|
+
for (const propName of propNames) {
|
|
66
|
+
const value = propMgr.Get(propName);
|
|
67
|
+
const resolvedValue = propMgr.Get2(propName);
|
|
68
|
+
templateData.properties[propName] = {
|
|
69
|
+
value: value[0],
|
|
70
|
+
evaluatedValue: resolvedValue[0],
|
|
71
|
+
type: value[1]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Extract dimension and annotation styles
|
|
77
|
+
if (args.includeStyles) {
|
|
78
|
+
templateData.styles = {
|
|
79
|
+
dimensions: {
|
|
80
|
+
textHeight: drawing.GetUserPreferenceDoubleValue(0), // swDetailingDimTextHeight
|
|
81
|
+
arrowSize: drawing.GetUserPreferenceDoubleValue(1), // swDetailingArrowLength
|
|
82
|
+
tolerance: drawing.GetUserPreferenceIntegerValue(20), // swDetailingDimTolerance
|
|
83
|
+
precision: drawing.GetUserPreferenceIntegerValue(21), // swDetailingDimPrecision
|
|
84
|
+
units: drawing.GetUserPreferenceIntegerValue(22) // swDetailingDimUnits
|
|
85
|
+
},
|
|
86
|
+
annotations: {
|
|
87
|
+
textHeight: drawing.GetUserPreferenceDoubleValue(5), // swDetailingNoteTextHeight
|
|
88
|
+
font: drawing.GetUserPreferenceStringValue(10), // swDetailingNoteFont
|
|
89
|
+
leaderStyle: drawing.GetUserPreferenceIntegerValue(30), // swDetailingNoteLeaderStyle
|
|
90
|
+
balloonStyle: drawing.GetUserPreferenceIntegerValue(31) // swDetailingBalloonStyle
|
|
91
|
+
},
|
|
92
|
+
tables: {
|
|
93
|
+
bomAnchor: drawing.GetUserPreferenceIntegerValue(40), // swDetailingBOMTableAnchor
|
|
94
|
+
bomFont: drawing.GetUserPreferenceStringValue(41), // swDetailingBOMTableFont
|
|
95
|
+
bomTextHeight: drawing.GetUserPreferenceDoubleValue(42) // swDetailingBOMTableTextHeight
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Extract view layout
|
|
100
|
+
if (args.includeViews) {
|
|
101
|
+
const firstView = drawing.GetFirstView();
|
|
102
|
+
let currentView = firstView.GetNextView();
|
|
103
|
+
while (currentView) {
|
|
104
|
+
const position = currentView.Position;
|
|
105
|
+
const outline = currentView.GetOutline();
|
|
106
|
+
templateData.views.push({
|
|
107
|
+
name: currentView.Name,
|
|
108
|
+
type: currentView.Type,
|
|
109
|
+
scale: currentView.ScaleDecimal,
|
|
110
|
+
position: { x: position[0], y: position[1] },
|
|
111
|
+
outline: {
|
|
112
|
+
min: { x: outline[0], y: outline[1] },
|
|
113
|
+
max: { x: outline[2], y: outline[3] }
|
|
114
|
+
},
|
|
115
|
+
displayMode: currentView.DisplayMode,
|
|
116
|
+
orientation: currentView.Orientation
|
|
117
|
+
});
|
|
118
|
+
currentView = currentView.GetNextView();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Save template configuration if requested
|
|
122
|
+
if (args.saveAs) {
|
|
123
|
+
const fs = require('fs');
|
|
124
|
+
fs.writeFileSync(args.saveAs, JSON.stringify(templateData, null, 2));
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
message: 'Template extracted successfully',
|
|
129
|
+
templateData,
|
|
130
|
+
propertyCount: Object.keys(templateData.properties).length,
|
|
131
|
+
viewCount: templateData.views.length
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return `Failed to extract template: ${error}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
// ============================================
|
|
140
|
+
// TEMPLATE APPLICATION
|
|
141
|
+
// ============================================
|
|
142
|
+
{
|
|
143
|
+
name: 'apply_drawing_template',
|
|
144
|
+
description: 'Apply template settings to a target drawing file',
|
|
145
|
+
inputSchema: z.object({
|
|
146
|
+
targetFile: z.string().describe('Path to the target drawing file'),
|
|
147
|
+
templateData: z.object({}).optional().describe('Template data object (from extract_drawing_template)'),
|
|
148
|
+
templateFile: z.string().optional().describe('Path to saved template JSON file'),
|
|
149
|
+
applyFormat: z.boolean().default(true).describe('Apply sheet format'),
|
|
150
|
+
applyProperties: z.boolean().default(true).describe('Apply custom properties'),
|
|
151
|
+
applyStyles: z.boolean().default(true).describe('Apply dimension/annotation styles'),
|
|
152
|
+
overwriteExisting: z.boolean().default(false).describe('Overwrite existing properties')
|
|
153
|
+
}),
|
|
154
|
+
handler: (args, swApi) => {
|
|
155
|
+
try {
|
|
156
|
+
// Load template data
|
|
157
|
+
let templateData = args.templateData;
|
|
158
|
+
if (!templateData && args.templateFile) {
|
|
159
|
+
const fs = require('fs');
|
|
160
|
+
templateData = JSON.parse(fs.readFileSync(args.templateFile, 'utf8'));
|
|
161
|
+
}
|
|
162
|
+
if (!templateData) {
|
|
163
|
+
throw new Error('No template data provided');
|
|
164
|
+
}
|
|
165
|
+
// Open target file
|
|
166
|
+
swApi.openModel(args.targetFile);
|
|
167
|
+
const model = swApi.getCurrentModel();
|
|
168
|
+
if (!model || model.GetType() !== 3) {
|
|
169
|
+
throw new Error('Target file is not a drawing document');
|
|
170
|
+
}
|
|
171
|
+
const drawing = model;
|
|
172
|
+
const sheet = drawing.GetCurrentSheet();
|
|
173
|
+
let changedItems = [];
|
|
174
|
+
// Apply sheet format
|
|
175
|
+
if (args.applyFormat && templateData.sheetFormat) {
|
|
176
|
+
const format = templateData.sheetFormat;
|
|
177
|
+
// Set sheet size and orientation
|
|
178
|
+
if (format.size) {
|
|
179
|
+
sheet.SetSize(format.size);
|
|
180
|
+
changedItems.push('Sheet size');
|
|
181
|
+
}
|
|
182
|
+
if (format.scale) {
|
|
183
|
+
sheet.SetScale(format.scale[0], format.scale[1]);
|
|
184
|
+
changedItems.push('Sheet scale');
|
|
185
|
+
}
|
|
186
|
+
if (format.templatePath) {
|
|
187
|
+
drawing.SetupSheet5(sheet.GetName(), format.size, format.scale[0], format.scale[1], format.firstAngle, format.templatePath, 0, 0, "", args.overwriteExisting);
|
|
188
|
+
changedItems.push('Sheet format');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Apply custom properties
|
|
192
|
+
if (args.applyProperties && templateData.properties) {
|
|
193
|
+
const propMgr = drawing.Extension.CustomPropertyManager("");
|
|
194
|
+
for (const [propName, propData] of Object.entries(templateData.properties)) {
|
|
195
|
+
const prop = propData;
|
|
196
|
+
// Check if property exists
|
|
197
|
+
const exists = propMgr.Get(propName)[0] !== "";
|
|
198
|
+
if (!exists || args.overwriteExisting) {
|
|
199
|
+
propMgr.Add3(propName, prop.type || 30, // swCustomInfoType_e
|
|
200
|
+
prop.value, 1 // overwrite if exists
|
|
201
|
+
);
|
|
202
|
+
changedItems.push(`Property: ${propName}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Apply dimension and annotation styles
|
|
207
|
+
if (args.applyStyles && templateData.styles) {
|
|
208
|
+
const styles = templateData.styles;
|
|
209
|
+
if (styles.dimensions) {
|
|
210
|
+
drawing.SetUserPreferenceDoubleValue(0, styles.dimensions.textHeight);
|
|
211
|
+
drawing.SetUserPreferenceDoubleValue(1, styles.dimensions.arrowSize);
|
|
212
|
+
drawing.SetUserPreferenceIntegerValue(20, styles.dimensions.tolerance);
|
|
213
|
+
drawing.SetUserPreferenceIntegerValue(21, styles.dimensions.precision);
|
|
214
|
+
drawing.SetUserPreferenceIntegerValue(22, styles.dimensions.units);
|
|
215
|
+
changedItems.push('Dimension styles');
|
|
216
|
+
}
|
|
217
|
+
if (styles.annotations) {
|
|
218
|
+
drawing.SetUserPreferenceDoubleValue(5, styles.annotations.textHeight);
|
|
219
|
+
drawing.SetUserPreferenceStringValue(10, styles.annotations.font);
|
|
220
|
+
drawing.SetUserPreferenceIntegerValue(30, styles.annotations.leaderStyle);
|
|
221
|
+
drawing.SetUserPreferenceIntegerValue(31, styles.annotations.balloonStyle);
|
|
222
|
+
changedItems.push('Annotation styles');
|
|
223
|
+
}
|
|
224
|
+
if (styles.tables) {
|
|
225
|
+
drawing.SetUserPreferenceIntegerValue(40, styles.tables.bomAnchor);
|
|
226
|
+
drawing.SetUserPreferenceStringValue(41, styles.tables.bomFont);
|
|
227
|
+
drawing.SetUserPreferenceDoubleValue(42, styles.tables.bomTextHeight);
|
|
228
|
+
changedItems.push('Table styles');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Rebuild drawing
|
|
232
|
+
drawing.ForceRebuild3(false);
|
|
233
|
+
return {
|
|
234
|
+
success: true,
|
|
235
|
+
message: `Template applied to ${args.targetFile}`,
|
|
236
|
+
changedItems,
|
|
237
|
+
changeCount: changedItems.length
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
return `Failed to apply template: ${error}`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
// ============================================
|
|
246
|
+
// BATCH TEMPLATE APPLICATION
|
|
247
|
+
// ============================================
|
|
248
|
+
{
|
|
249
|
+
name: 'batch_apply_template',
|
|
250
|
+
description: 'Apply template to multiple child drawing files',
|
|
251
|
+
inputSchema: z.object({
|
|
252
|
+
parentFile: z.string().describe('Path to parent drawing file to use as template'),
|
|
253
|
+
childFiles: z.array(z.string()).describe('Array of child drawing file paths'),
|
|
254
|
+
includeSubfolders: z.boolean().default(false).describe('Process files in subfolders'),
|
|
255
|
+
filePattern: z.string().default('*.SLDDRW').describe('File pattern for automatic discovery'),
|
|
256
|
+
applyFormat: z.boolean().default(true).describe('Apply sheet format'),
|
|
257
|
+
applyProperties: z.boolean().default(true).describe('Apply custom properties'),
|
|
258
|
+
applyStyles: z.boolean().default(true).describe('Apply dimension/annotation styles'),
|
|
259
|
+
overwriteExisting: z.boolean().default(false).describe('Overwrite existing properties'),
|
|
260
|
+
saveReport: z.string().optional().describe('Path to save processing report')
|
|
261
|
+
}),
|
|
262
|
+
handler: async (args, swApi) => {
|
|
263
|
+
try {
|
|
264
|
+
const report = {
|
|
265
|
+
startTime: new Date().toISOString(),
|
|
266
|
+
parentFile: args.parentFile,
|
|
267
|
+
processedFiles: [],
|
|
268
|
+
failedFiles: [],
|
|
269
|
+
summary: {
|
|
270
|
+
total: 0,
|
|
271
|
+
successful: 0,
|
|
272
|
+
failed: 0
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
// First, extract template from parent
|
|
276
|
+
swApi.openModel(args.parentFile);
|
|
277
|
+
const model = swApi.getCurrentModel();
|
|
278
|
+
if (!model || model.GetType() !== 3) {
|
|
279
|
+
throw new Error('Parent file is not a drawing document');
|
|
280
|
+
}
|
|
281
|
+
// Extract template data
|
|
282
|
+
const templateData = await extractTemplateData(model, swApi);
|
|
283
|
+
// Get list of files to process
|
|
284
|
+
let filesToProcess = [...args.childFiles];
|
|
285
|
+
// Add files from folder if pattern matching requested
|
|
286
|
+
if (args.includeSubfolders && args.filePattern) {
|
|
287
|
+
const fs = require('fs');
|
|
288
|
+
const path = require('path');
|
|
289
|
+
const parentDir = path.dirname(args.parentFile);
|
|
290
|
+
const findFiles = (dir, pattern) => {
|
|
291
|
+
let results = [];
|
|
292
|
+
const files = fs.readdirSync(dir);
|
|
293
|
+
for (const file of files) {
|
|
294
|
+
const fullPath = path.join(dir, file);
|
|
295
|
+
const stat = fs.statSync(fullPath);
|
|
296
|
+
if (stat.isDirectory() && args.includeSubfolders) {
|
|
297
|
+
results = results.concat(findFiles(fullPath, pattern));
|
|
298
|
+
}
|
|
299
|
+
else if (file.match(pattern.replace('*', '.*'))) {
|
|
300
|
+
results.push(fullPath);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return results;
|
|
304
|
+
};
|
|
305
|
+
const discoveredFiles = findFiles(parentDir, args.filePattern);
|
|
306
|
+
filesToProcess = [...new Set([...filesToProcess, ...discoveredFiles])];
|
|
307
|
+
// Remove parent file from list
|
|
308
|
+
filesToProcess = filesToProcess.filter(f => f !== args.parentFile);
|
|
309
|
+
}
|
|
310
|
+
report.summary.total = filesToProcess.length;
|
|
311
|
+
// Process each file
|
|
312
|
+
for (const childFile of filesToProcess) {
|
|
313
|
+
const fileReport = {
|
|
314
|
+
file: childFile,
|
|
315
|
+
startTime: new Date().toISOString(),
|
|
316
|
+
changes: [],
|
|
317
|
+
errors: []
|
|
318
|
+
};
|
|
319
|
+
try {
|
|
320
|
+
// Open child file
|
|
321
|
+
swApi.openModel(childFile);
|
|
322
|
+
const childModel = swApi.getCurrentModel();
|
|
323
|
+
if (!childModel || childModel.GetType() !== 3) {
|
|
324
|
+
throw new Error('Not a drawing document');
|
|
325
|
+
}
|
|
326
|
+
// Apply template
|
|
327
|
+
const result = await applyTemplateToDrawing(childModel, templateData, {
|
|
328
|
+
applyFormat: args.applyFormat,
|
|
329
|
+
applyProperties: args.applyProperties,
|
|
330
|
+
applyStyles: args.applyStyles,
|
|
331
|
+
overwriteExisting: args.overwriteExisting
|
|
332
|
+
}, swApi);
|
|
333
|
+
fileReport.changes = result.changes;
|
|
334
|
+
fileReport.endTime = new Date().toISOString();
|
|
335
|
+
fileReport.success = true;
|
|
336
|
+
// Save and close
|
|
337
|
+
childModel.Save3(1, 0, 0); // swSaveAsOptions_Silent
|
|
338
|
+
swApi.closeModel(true);
|
|
339
|
+
report.processedFiles.push(fileReport);
|
|
340
|
+
report.summary.successful++;
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
fileReport.errors.push(String(error));
|
|
344
|
+
fileReport.endTime = new Date().toISOString();
|
|
345
|
+
fileReport.success = false;
|
|
346
|
+
report.failedFiles.push(fileReport);
|
|
347
|
+
report.summary.failed++;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
report.endTime = new Date().toISOString();
|
|
351
|
+
// Save report if requested
|
|
352
|
+
if (args.saveReport) {
|
|
353
|
+
const fs = require('fs');
|
|
354
|
+
fs.writeFileSync(args.saveReport, JSON.stringify(report, null, 2));
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
success: true,
|
|
358
|
+
message: `Batch template application completed`,
|
|
359
|
+
summary: report.summary,
|
|
360
|
+
report: args.saveReport ? `Report saved to ${args.saveReport}` : report
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
return `Failed to batch apply template: ${error}`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
// ============================================
|
|
369
|
+
// TEMPLATE COMPARISON
|
|
370
|
+
// ============================================
|
|
371
|
+
{
|
|
372
|
+
name: 'compare_drawing_templates',
|
|
373
|
+
description: 'Compare template settings between two drawings',
|
|
374
|
+
inputSchema: z.object({
|
|
375
|
+
file1: z.string().describe('First drawing file path'),
|
|
376
|
+
file2: z.string().describe('Second drawing file path'),
|
|
377
|
+
compareFormat: z.boolean().default(true).describe('Compare sheet formats'),
|
|
378
|
+
compareProperties: z.boolean().default(true).describe('Compare custom properties'),
|
|
379
|
+
compareStyles: z.boolean().default(true).describe('Compare styles')
|
|
380
|
+
}),
|
|
381
|
+
handler: (args, swApi) => {
|
|
382
|
+
try {
|
|
383
|
+
// Extract templates from both files
|
|
384
|
+
const template1 = extractTemplateFromFile(args.file1, swApi);
|
|
385
|
+
const template2 = extractTemplateFromFile(args.file2, swApi);
|
|
386
|
+
const differences = {
|
|
387
|
+
format: [],
|
|
388
|
+
properties: [],
|
|
389
|
+
styles: []
|
|
390
|
+
};
|
|
391
|
+
// Compare sheet formats
|
|
392
|
+
if (args.compareFormat) {
|
|
393
|
+
const format1 = template1.sheetFormat;
|
|
394
|
+
const format2 = template2.sheetFormat;
|
|
395
|
+
if (format1.size !== format2.size) {
|
|
396
|
+
differences.format.push({
|
|
397
|
+
attribute: 'Sheet Size',
|
|
398
|
+
file1: format1.size,
|
|
399
|
+
file2: format2.size
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (JSON.stringify(format1.scale) !== JSON.stringify(format2.scale)) {
|
|
403
|
+
differences.format.push({
|
|
404
|
+
attribute: 'Scale',
|
|
405
|
+
file1: format1.scale,
|
|
406
|
+
file2: format2.scale
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
// Compare properties
|
|
411
|
+
if (args.compareProperties) {
|
|
412
|
+
const props1 = template1.properties;
|
|
413
|
+
const props2 = template2.properties;
|
|
414
|
+
// Check properties in file1
|
|
415
|
+
for (const [key, value] of Object.entries(props1)) {
|
|
416
|
+
if (!props2[key]) {
|
|
417
|
+
differences.properties.push({
|
|
418
|
+
property: key,
|
|
419
|
+
file1: value,
|
|
420
|
+
file2: 'Not present'
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
else if (JSON.stringify(value) !== JSON.stringify(props2[key])) {
|
|
424
|
+
differences.properties.push({
|
|
425
|
+
property: key,
|
|
426
|
+
file1: value,
|
|
427
|
+
file2: props2[key]
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Check properties only in file2
|
|
432
|
+
for (const key of Object.keys(props2)) {
|
|
433
|
+
if (!props1[key]) {
|
|
434
|
+
differences.properties.push({
|
|
435
|
+
property: key,
|
|
436
|
+
file1: 'Not present',
|
|
437
|
+
file2: props2[key]
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
// Compare styles
|
|
443
|
+
if (args.compareStyles) {
|
|
444
|
+
const styles1 = template1.styles;
|
|
445
|
+
const styles2 = template2.styles;
|
|
446
|
+
const compareStyleCategory = (category) => {
|
|
447
|
+
const cat1 = styles1[category];
|
|
448
|
+
const cat2 = styles2[category];
|
|
449
|
+
for (const [key, value] of Object.entries(cat1 || {})) {
|
|
450
|
+
if (cat2[key] !== value) {
|
|
451
|
+
differences.styles.push({
|
|
452
|
+
category,
|
|
453
|
+
setting: key,
|
|
454
|
+
file1: value,
|
|
455
|
+
file2: cat2[key]
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
compareStyleCategory('dimensions');
|
|
461
|
+
compareStyleCategory('annotations');
|
|
462
|
+
compareStyleCategory('tables');
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
success: true,
|
|
466
|
+
message: 'Template comparison completed',
|
|
467
|
+
file1: args.file1,
|
|
468
|
+
file2: args.file2,
|
|
469
|
+
differences,
|
|
470
|
+
differenceCount: {
|
|
471
|
+
format: differences.format.length,
|
|
472
|
+
properties: differences.properties.length,
|
|
473
|
+
styles: differences.styles.length,
|
|
474
|
+
total: differences.format.length + differences.properties.length + differences.styles.length
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
return `Failed to compare templates: ${error}`;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
// ============================================
|
|
484
|
+
// TEMPLATE LIBRARY MANAGEMENT
|
|
485
|
+
// ============================================
|
|
486
|
+
{
|
|
487
|
+
name: 'save_template_to_library',
|
|
488
|
+
description: 'Save a drawing template to a reusable library',
|
|
489
|
+
inputSchema: z.object({
|
|
490
|
+
sourceFile: z.string().describe('Source drawing file'),
|
|
491
|
+
templateName: z.string().describe('Name for the template'),
|
|
492
|
+
category: z.string().default('General').describe('Template category'),
|
|
493
|
+
description: z.string().optional().describe('Template description'),
|
|
494
|
+
tags: z.array(z.string()).default([]).describe('Tags for searching'),
|
|
495
|
+
libraryPath: z.string().default('./templates').describe('Library folder path')
|
|
496
|
+
}),
|
|
497
|
+
handler: (args, swApi) => {
|
|
498
|
+
try {
|
|
499
|
+
const fs = require('fs');
|
|
500
|
+
const path = require('path');
|
|
501
|
+
// Ensure library directory exists
|
|
502
|
+
if (!fs.existsSync(args.libraryPath)) {
|
|
503
|
+
fs.mkdirSync(args.libraryPath, { recursive: true });
|
|
504
|
+
}
|
|
505
|
+
// Create category folder
|
|
506
|
+
const categoryPath = path.join(args.libraryPath, args.category);
|
|
507
|
+
if (!fs.existsSync(categoryPath)) {
|
|
508
|
+
fs.mkdirSync(categoryPath, { recursive: true });
|
|
509
|
+
}
|
|
510
|
+
// Extract template data
|
|
511
|
+
const templateData = extractTemplateFromFile(args.sourceFile, swApi);
|
|
512
|
+
// Add metadata
|
|
513
|
+
const libraryTemplate = {
|
|
514
|
+
...templateData,
|
|
515
|
+
metadata: {
|
|
516
|
+
name: args.templateName,
|
|
517
|
+
category: args.category,
|
|
518
|
+
description: args.description,
|
|
519
|
+
tags: args.tags,
|
|
520
|
+
sourceFile: args.sourceFile,
|
|
521
|
+
createdAt: new Date().toISOString(),
|
|
522
|
+
version: '1.0.0'
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
// Save template
|
|
526
|
+
const templateFileName = `${args.templateName.replace(/[^a-zA-Z0-9]/g, '_')}.json`;
|
|
527
|
+
const templatePath = path.join(categoryPath, templateFileName);
|
|
528
|
+
fs.writeFileSync(templatePath, JSON.stringify(libraryTemplate, null, 2));
|
|
529
|
+
// Update library index
|
|
530
|
+
const indexPath = path.join(args.libraryPath, 'index.json');
|
|
531
|
+
let index = { templates: [] };
|
|
532
|
+
if (fs.existsSync(indexPath)) {
|
|
533
|
+
index = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
|
|
534
|
+
}
|
|
535
|
+
index.templates.push({
|
|
536
|
+
name: args.templateName,
|
|
537
|
+
category: args.category,
|
|
538
|
+
description: args.description,
|
|
539
|
+
tags: args.tags,
|
|
540
|
+
path: templatePath,
|
|
541
|
+
createdAt: new Date().toISOString()
|
|
542
|
+
});
|
|
543
|
+
fs.writeFileSync(indexPath, JSON.stringify(index, null, 2));
|
|
544
|
+
return {
|
|
545
|
+
success: true,
|
|
546
|
+
message: `Template saved to library as '${args.templateName}'`,
|
|
547
|
+
path: templatePath,
|
|
548
|
+
category: args.category,
|
|
549
|
+
tags: args.tags
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
return `Failed to save template to library: ${error}`;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
name: 'list_template_library',
|
|
559
|
+
description: 'List all templates in the library',
|
|
560
|
+
inputSchema: z.object({
|
|
561
|
+
libraryPath: z.string().default('./templates').describe('Library folder path'),
|
|
562
|
+
category: z.string().optional().describe('Filter by category'),
|
|
563
|
+
tags: z.array(z.string()).optional().describe('Filter by tags')
|
|
564
|
+
}),
|
|
565
|
+
handler: (args) => {
|
|
566
|
+
try {
|
|
567
|
+
const fs = require('fs');
|
|
568
|
+
const path = require('path');
|
|
569
|
+
const indexPath = path.join(args.libraryPath, 'index.json');
|
|
570
|
+
if (!fs.existsSync(indexPath)) {
|
|
571
|
+
return {
|
|
572
|
+
success: true,
|
|
573
|
+
message: 'Template library is empty',
|
|
574
|
+
templates: []
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const index = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
|
|
578
|
+
let templates = index.templates;
|
|
579
|
+
// Filter by category
|
|
580
|
+
if (args.category) {
|
|
581
|
+
templates = templates.filter((t) => t.category === args.category);
|
|
582
|
+
}
|
|
583
|
+
// Filter by tags
|
|
584
|
+
if (args.tags && args.tags.length > 0) {
|
|
585
|
+
templates = templates.filter((t) => args.tags.some((tag) => t.tags.includes(tag)));
|
|
586
|
+
}
|
|
587
|
+
return {
|
|
588
|
+
success: true,
|
|
589
|
+
message: `Found ${templates.length} templates`,
|
|
590
|
+
templates,
|
|
591
|
+
categories: [...new Set(index.templates.map((t) => t.category))],
|
|
592
|
+
allTags: [...new Set(index.templates.flatMap((t) => t.tags))]
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
return `Failed to list template library: ${error}`;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
];
|
|
601
|
+
// Helper functions
|
|
602
|
+
function extractTemplateFromFile(filePath, swApi) {
|
|
603
|
+
swApi.openModel(filePath);
|
|
604
|
+
const model = swApi.getCurrentModel();
|
|
605
|
+
if (!model || model.GetType() !== 3) {
|
|
606
|
+
throw new Error('File is not a drawing document');
|
|
607
|
+
}
|
|
608
|
+
return extractTemplateData(model, swApi);
|
|
609
|
+
}
|
|
610
|
+
function extractTemplateData(drawing, swApi) {
|
|
611
|
+
// Implementation would extract all template data
|
|
612
|
+
// This is a simplified version
|
|
613
|
+
return {
|
|
614
|
+
sheetFormat: {},
|
|
615
|
+
properties: {},
|
|
616
|
+
styles: {}
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function applyTemplateToDrawing(drawing, templateData, options, swApi) {
|
|
620
|
+
// Implementation would apply template settings
|
|
621
|
+
// This is a simplified version
|
|
622
|
+
return {
|
|
623
|
+
changes: ['Applied template']
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
//# sourceMappingURL=template-manager.js.map
|