indesign-cli 0.2.0__py3-none-any.whl
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.
- cli_anything/indesign/README.md +32 -0
- cli_anything/indesign/__init__.py +1 -0
- cli_anything/indesign/__main__.py +5 -0
- cli_anything/indesign/core/artifacts.py +57 -0
- cli_anything/indesign/core/catalog.py +405 -0
- cli_anything/indesign/core/domains.py +178 -0
- cli_anything/indesign/core/envelope.py +65 -0
- cli_anything/indesign/core/errors.py +30 -0
- cli_anything/indesign/core/health.py +46 -0
- cli_anything/indesign/core/hidden_backend.py +116 -0
- cli_anything/indesign/core/hidden_handler_schemas.py +223 -0
- cli_anything/indesign/core/mcp_backend.py +152 -0
- cli_anything/indesign/core/node_setup.py +35 -0
- cli_anything/indesign/core/paths.py +41 -0
- cli_anything/indesign/core/plugins/__init__.py +2 -0
- cli_anything/indesign/core/plugins/backend.py +90 -0
- cli_anything/indesign/core/plugins/discovery.py +69 -0
- cli_anything/indesign/core/plugins/host_actions.py +76 -0
- cli_anything/indesign/core/plugins/install.py +38 -0
- cli_anything/indesign/core/plugins/manifest.py +279 -0
- cli_anything/indesign/core/plugins/validate.py +181 -0
- cli_anything/indesign/core/router.py +217 -0
- cli_anything/indesign/core/runtime.py +59 -0
- cli_anything/indesign/core/scripts.py +44 -0
- cli_anything/indesign/core/session.py +68 -0
- cli_anything/indesign/indesign_cli.py +320 -0
- cli_anything/indesign/node/hidden_handler_bridge.mjs +111 -0
- cli_anything/indesign/server/package-lock.json +168 -0
- cli_anything/indesign/server/package.json +45 -0
- cli_anything/indesign/server/src/advanced/index.js +76 -0
- cli_anything/indesign/server/src/core/InDesignMCPServer.js +273 -0
- cli_anything/indesign/server/src/core/scriptExecutor.js +271 -0
- cli_anything/indesign/server/src/core/sessionManager.js +545 -0
- cli_anything/indesign/server/src/handlers/advancedTemplateHandlers.js +1072 -0
- cli_anything/indesign/server/src/handlers/bookHandlers.js +490 -0
- cli_anything/indesign/server/src/handlers/documentHandlers.js +1472 -0
- cli_anything/indesign/server/src/handlers/exportHandlers.js +208 -0
- cli_anything/indesign/server/src/handlers/graphicsHandlers.js +605 -0
- cli_anything/indesign/server/src/handlers/groupHandlers.js +358 -0
- cli_anything/indesign/server/src/handlers/helpHandlers.js +347 -0
- cli_anything/indesign/server/src/handlers/index.js +77 -0
- cli_anything/indesign/server/src/handlers/layerHandlers.js +75 -0
- cli_anything/indesign/server/src/handlers/masterSpreadHandlers.js +451 -0
- cli_anything/indesign/server/src/handlers/pageHandlers.js +698 -0
- cli_anything/indesign/server/src/handlers/pageItemHandlers.js +704 -0
- cli_anything/indesign/server/src/handlers/presentationHandlers.js +220 -0
- cli_anything/indesign/server/src/handlers/spreadHandlers.js +348 -0
- cli_anything/indesign/server/src/handlers/styleHandlers.js +458 -0
- cli_anything/indesign/server/src/handlers/textHandlers.js +431 -0
- cli_anything/indesign/server/src/handlers/utilityHandlers.js +83 -0
- cli_anything/indesign/server/src/index.js +17 -0
- cli_anything/indesign/server/src/types/index.js +106 -0
- cli_anything/indesign/server/src/types/toolDefinitionsAdvancedTemplates.js +144 -0
- cli_anything/indesign/server/src/types/toolDefinitionsBook.js +224 -0
- cli_anything/indesign/server/src/types/toolDefinitionsContent.js +353 -0
- cli_anything/indesign/server/src/types/toolDefinitionsDocument.js +409 -0
- cli_anything/indesign/server/src/types/toolDefinitionsExport.js +65 -0
- cli_anything/indesign/server/src/types/toolDefinitionsLayer.js +40 -0
- cli_anything/indesign/server/src/types/toolDefinitionsMasterSpread.js +160 -0
- cli_anything/indesign/server/src/types/toolDefinitionsPage.js +271 -0
- cli_anything/indesign/server/src/types/toolDefinitionsPageItemGroup.js +437 -0
- cli_anything/indesign/server/src/types/toolDefinitionsPresentation.js +83 -0
- cli_anything/indesign/server/src/types/toolDefinitionsSpread.js +158 -0
- cli_anything/indesign/server/src/types/toolDefinitionsUtility.js +40 -0
- cli_anything/indesign/server/src/utils/stringUtils.js +107 -0
- cli_anything/indesign/skills/SKILL.md +198 -0
- indesign_cli-0.2.0.dist-info/METADATA +267 -0
- indesign_cli-0.2.0.dist-info/RECORD +72 -0
- indesign_cli-0.2.0.dist-info/WHEEL +5 -0
- indesign_cli-0.2.0.dist-info/entry_points.txt +3 -0
- indesign_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
- indesign_cli-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive Document management handlers
|
|
3
|
+
* Merged from documentHandlers.js and documentAdvancedHandlers.js
|
|
4
|
+
*/
|
|
5
|
+
import { ScriptExecutor } from '../core/scriptExecutor.js';
|
|
6
|
+
import { formatResponse, formatErrorResponse, escapeJsxString, escapeFilePathForJsx } from '../utils/stringUtils.js';
|
|
7
|
+
import { sessionManager } from '../core/sessionManager.js';
|
|
8
|
+
|
|
9
|
+
export class DocumentHandlers {
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to ensure we have an active document
|
|
12
|
+
*/
|
|
13
|
+
static async ensureActiveDocument() {
|
|
14
|
+
const script = [
|
|
15
|
+
'try {',
|
|
16
|
+
' if (app.documents.length === 0) {',
|
|
17
|
+
' "No document open";',
|
|
18
|
+
' } else {',
|
|
19
|
+
' var doc = app.activeDocument;',
|
|
20
|
+
' if (!doc) {',
|
|
21
|
+
' // If no active document, try to get the first one',
|
|
22
|
+
' if (app.documents.length > 0) {',
|
|
23
|
+
' doc = app.documents[0];',
|
|
24
|
+
' app.activeDocument = doc;',
|
|
25
|
+
' "Document activated: " + doc.name;',
|
|
26
|
+
' } else {',
|
|
27
|
+
' "No document open";',
|
|
28
|
+
' }',
|
|
29
|
+
' } else {',
|
|
30
|
+
' "Document already active: " + doc.name;',
|
|
31
|
+
' }',
|
|
32
|
+
' }',
|
|
33
|
+
'} catch (error) {',
|
|
34
|
+
' "Error ensuring active document: " + error.message;',
|
|
35
|
+
'}'
|
|
36
|
+
].join('\n');
|
|
37
|
+
|
|
38
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
39
|
+
return formatResponse(result, "Ensure Active Document");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get information about the active document
|
|
44
|
+
*/
|
|
45
|
+
static async getDocumentInfo() {
|
|
46
|
+
const script = [
|
|
47
|
+
'try {',
|
|
48
|
+
' if (app.documents.length === 0) {',
|
|
49
|
+
' "No document open";',
|
|
50
|
+
' } else {',
|
|
51
|
+
' var doc = app.activeDocument;',
|
|
52
|
+
' if (!doc) {',
|
|
53
|
+
' // If no active document, try to get the first one',
|
|
54
|
+
' if (app.documents.length > 0) {',
|
|
55
|
+
' doc = app.documents[0];',
|
|
56
|
+
' app.activeDocument = doc;',
|
|
57
|
+
' } else {',
|
|
58
|
+
' "No document open";',
|
|
59
|
+
' }',
|
|
60
|
+
' }',
|
|
61
|
+
' ',
|
|
62
|
+
' var info = "=== DOCUMENT INFO ===\\n";',
|
|
63
|
+
' info += "Name: " + doc.name + "\\n";',
|
|
64
|
+
' try {',
|
|
65
|
+
' info += "Path: " + doc.filePath + "\\n";',
|
|
66
|
+
' } catch (e) {',
|
|
67
|
+
' info += "Path: Unsaved\\n";',
|
|
68
|
+
' }',
|
|
69
|
+
' info += "Pages: " + doc.pages.length + "\\n";',
|
|
70
|
+
' info += "Spreads: " + doc.spreads.length + "\\n";',
|
|
71
|
+
' info += "Layers: " + doc.layers.length + "\\n";',
|
|
72
|
+
' info += "Master Spreads: " + doc.masterSpreads.length + "\\n";',
|
|
73
|
+
' info += "Document Width: " + doc.documentPreferences.pageWidth + "\\n";',
|
|
74
|
+
' info += "Document Height: " + doc.documentPreferences.pageHeight + "\\n";',
|
|
75
|
+
' info += "Facing Pages: " + doc.documentPreferences.facingPages + "\\n";',
|
|
76
|
+
' info += "Page Orientation: " + doc.documentPreferences.pageOrientation + "\\n";',
|
|
77
|
+
' info += "Bleed Top: " + doc.documentPreferences.documentBleedTopOffset + "\\n";',
|
|
78
|
+
' info += "Bleed Bottom: " + doc.documentPreferences.documentBleedBottomOffset + "\\n";',
|
|
79
|
+
' info += "Bleed Inside: " + doc.documentPreferences.documentBleedInsideOrLeftOffset + "\\n";',
|
|
80
|
+
' info += "Bleed Outside: " + doc.documentPreferences.documentBleedOutsideOrRightOffset + "\\n";',
|
|
81
|
+
' info += "Margin Top: " + doc.marginPreferences.top + "\\n";',
|
|
82
|
+
' info += "Margin Bottom: " + doc.marginPreferences.bottom + "\\n";',
|
|
83
|
+
' info += "Margin Left: " + doc.marginPreferences.left + "\\n";',
|
|
84
|
+
' info += "Margin Right: " + doc.marginPreferences.right + "\\n";',
|
|
85
|
+
' info;',
|
|
86
|
+
' }',
|
|
87
|
+
'} catch (error) {',
|
|
88
|
+
' "Error getting document info: " + error.message;',
|
|
89
|
+
'}'
|
|
90
|
+
].join('\n');
|
|
91
|
+
|
|
92
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
93
|
+
|
|
94
|
+
// Store document info in session manager
|
|
95
|
+
if (result.includes("=== DOCUMENT INFO ===")) {
|
|
96
|
+
const docInfo = {
|
|
97
|
+
name: result.match(/Name: (.+)/)?.[1] || 'Unknown',
|
|
98
|
+
path: result.match(/Path: (.+)/)?.[1] || 'Unsaved',
|
|
99
|
+
pages: parseInt(result.match(/Pages: (\d+)/)?.[1] || '0'),
|
|
100
|
+
width: parseFloat(result.match(/Document Width: ([\d.]+)/)?.[1] || '0'),
|
|
101
|
+
height: parseFloat(result.match(/Document Height: ([\d.]+)/)?.[1] || '0')
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
sessionManager.setActiveDocument(docInfo);
|
|
105
|
+
sessionManager.setPageDimensions({
|
|
106
|
+
width: docInfo.width,
|
|
107
|
+
height: docInfo.height
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return formatResponse(result, "Get Document Info");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create a new document
|
|
116
|
+
*/
|
|
117
|
+
static async createDocument(args) {
|
|
118
|
+
const {
|
|
119
|
+
width = 210,
|
|
120
|
+
height = 297,
|
|
121
|
+
pages = 1,
|
|
122
|
+
facingPages = false,
|
|
123
|
+
pageOrientation = 'PORTRAIT',
|
|
124
|
+
bleedTop = 3,
|
|
125
|
+
bleedBottom = 3,
|
|
126
|
+
bleedInside = 3,
|
|
127
|
+
bleedOutside = 3,
|
|
128
|
+
marginTop = 20,
|
|
129
|
+
marginBottom = 20,
|
|
130
|
+
marginLeft = 20,
|
|
131
|
+
marginRight = 20
|
|
132
|
+
} = args;
|
|
133
|
+
|
|
134
|
+
const script = [
|
|
135
|
+
'try {',
|
|
136
|
+
' // Create the document with basic parameters',
|
|
137
|
+
' var doc = app.documents.add();',
|
|
138
|
+
'',
|
|
139
|
+
' // Set document preferences after creation',
|
|
140
|
+
` doc.documentPreferences.pageWidth = ${width};`,
|
|
141
|
+
` doc.documentPreferences.pageHeight = ${height};`,
|
|
142
|
+
` doc.documentPreferences.facingPages = ${facingPages};`,
|
|
143
|
+
` doc.documentPreferences.pageOrientation = PageOrientation.${pageOrientation === 'PORTRAIT' ? 'PORTRAIT' : 'LANDSCAPE'};`,
|
|
144
|
+
` doc.documentPreferences.documentBleedTopOffset = ${bleedTop};`,
|
|
145
|
+
` doc.documentPreferences.documentBleedBottomOffset = ${bleedBottom};`,
|
|
146
|
+
` doc.documentPreferences.documentBleedInsideOrLeftOffset = ${bleedInside};`,
|
|
147
|
+
` doc.documentPreferences.documentBleedOutsideOrRightOffset = ${bleedOutside};`,
|
|
148
|
+
` doc.marginPreferences.top = ${marginTop};`,
|
|
149
|
+
` doc.marginPreferences.bottom = ${marginBottom};`,
|
|
150
|
+
` doc.marginPreferences.left = ${marginLeft};`,
|
|
151
|
+
` doc.marginPreferences.right = ${marginRight};`,
|
|
152
|
+
'',
|
|
153
|
+
' // Ensure the document is active',
|
|
154
|
+
' app.activeDocument = doc;',
|
|
155
|
+
'',
|
|
156
|
+
' // Verify the document is active and return success',
|
|
157
|
+
' if (app.activeDocument === doc) {',
|
|
158
|
+
' "Document created and activated successfully. Document name: " + doc.name;',
|
|
159
|
+
' } else {',
|
|
160
|
+
' "Document created but activation failed";',
|
|
161
|
+
' }',
|
|
162
|
+
'} catch (error) {',
|
|
163
|
+
' "Error creating document: " + error.message;',
|
|
164
|
+
'}'
|
|
165
|
+
].join('\n');
|
|
166
|
+
|
|
167
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
168
|
+
|
|
169
|
+
// Check if the operation was successful
|
|
170
|
+
const isSuccess = result.includes("Document created and activated successfully");
|
|
171
|
+
|
|
172
|
+
if (isSuccess) {
|
|
173
|
+
// Store document info in session manager
|
|
174
|
+
sessionManager.setActiveDocument({
|
|
175
|
+
name: result.match(/Document name: (.+)/)?.[1] || 'New Document',
|
|
176
|
+
path: 'Unsaved',
|
|
177
|
+
pages: pages,
|
|
178
|
+
width: width,
|
|
179
|
+
height: height
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
sessionManager.setPageDimensions({
|
|
183
|
+
width: width,
|
|
184
|
+
height: height
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return isSuccess ?
|
|
189
|
+
formatResponse(result, "Create Document") :
|
|
190
|
+
formatErrorResponse(result, "Create Document");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Open an existing document
|
|
195
|
+
*/
|
|
196
|
+
static async openDocument(args) {
|
|
197
|
+
const { filePath } = args;
|
|
198
|
+
const escapedFilePath = escapeFilePathForJsx(filePath);
|
|
199
|
+
|
|
200
|
+
const script = [
|
|
201
|
+
'var file = File("' + escapedFilePath + '");',
|
|
202
|
+
'if (!file.exists) {',
|
|
203
|
+
` "File not found: ${escapedFilePath}";`,
|
|
204
|
+
'} else {',
|
|
205
|
+
' app.open(file);',
|
|
206
|
+
` "Document opened: ${escapedFilePath}";`,
|
|
207
|
+
'}'
|
|
208
|
+
].join('\n');
|
|
209
|
+
|
|
210
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
211
|
+
return formatResponse(result, "Open Document");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Save the active document
|
|
216
|
+
*/
|
|
217
|
+
static async saveDocument(args) {
|
|
218
|
+
const { filePath } = args;
|
|
219
|
+
const escapedFilePath = escapeFilePathForJsx(filePath);
|
|
220
|
+
|
|
221
|
+
const script = [
|
|
222
|
+
'if (app.documents.length === 0) {',
|
|
223
|
+
' "No document open";',
|
|
224
|
+
'} else {',
|
|
225
|
+
' var doc = app.activeDocument;',
|
|
226
|
+
' var file = File("' + escapedFilePath + '");',
|
|
227
|
+
' try {',
|
|
228
|
+
' doc.save(file);',
|
|
229
|
+
` "Document saved: ${escapedFilePath}";`,
|
|
230
|
+
' } catch (error) {',
|
|
231
|
+
' "Error saving document: " + error.message;',
|
|
232
|
+
' }',
|
|
233
|
+
'}'
|
|
234
|
+
].join('\n');
|
|
235
|
+
|
|
236
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
237
|
+
return formatResponse(result, "Save Document");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Close the active document
|
|
242
|
+
*/
|
|
243
|
+
static async closeDocument() {
|
|
244
|
+
const script = [
|
|
245
|
+
'try {',
|
|
246
|
+
' if (app.documents.length === 0) {',
|
|
247
|
+
' "No document to close";',
|
|
248
|
+
' } else {',
|
|
249
|
+
' var doc = app.activeDocument;',
|
|
250
|
+
' if (!doc) {',
|
|
251
|
+
' // If no active document, try to get the first one',
|
|
252
|
+
' if (app.documents.length > 0) {',
|
|
253
|
+
' doc = app.documents[0];',
|
|
254
|
+
' } else {',
|
|
255
|
+
' "No document to close";',
|
|
256
|
+
' }',
|
|
257
|
+
' }',
|
|
258
|
+
' ',
|
|
259
|
+
' var docName = doc.name;',
|
|
260
|
+
' doc.close(SaveOptions.NO);',
|
|
261
|
+
' "Document closed successfully: " + docName;',
|
|
262
|
+
' }',
|
|
263
|
+
'} catch (error) {',
|
|
264
|
+
' "Error closing document: " + error.message;',
|
|
265
|
+
'}'
|
|
266
|
+
].join('\n');
|
|
267
|
+
|
|
268
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
269
|
+
return formatResponse(result, "Close Document");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// =================== DOCUMENT ADVANCED TOOLS ===================
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Run preflight on the document
|
|
276
|
+
*/
|
|
277
|
+
static async preflightDocument(args) {
|
|
278
|
+
const { profile = 'Basic', includeWarnings = true } = args;
|
|
279
|
+
const escapedProfile = escapeJsxString(profile);
|
|
280
|
+
|
|
281
|
+
const script = [
|
|
282
|
+
'if (app.documents.length === 0) {',
|
|
283
|
+
' "No document open";',
|
|
284
|
+
'} else {',
|
|
285
|
+
' var doc = app.activeDocument;',
|
|
286
|
+
' try {',
|
|
287
|
+
` doc.preflight("${escapedProfile}", ${includeWarnings});`,
|
|
288
|
+
' "Document preflighted successfully";',
|
|
289
|
+
' } catch (error) {',
|
|
290
|
+
' "Error preflighting document: " + error.message;',
|
|
291
|
+
' }',
|
|
292
|
+
'}'
|
|
293
|
+
].join('\n');
|
|
294
|
+
|
|
295
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
296
|
+
return formatResponse(result, "Preflight Document");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Zoom to fit page in view
|
|
301
|
+
*/
|
|
302
|
+
static async zoomToPage(args) {
|
|
303
|
+
const { pageIndex, zoomLevel = 100 } = args;
|
|
304
|
+
|
|
305
|
+
const script = [
|
|
306
|
+
'if (app.documents.length === 0) {',
|
|
307
|
+
' "No document open";',
|
|
308
|
+
'} else {',
|
|
309
|
+
' var doc = app.activeDocument;',
|
|
310
|
+
` if (${pageIndex} >= doc.pages.length) {`,
|
|
311
|
+
' "Page index out of range";',
|
|
312
|
+
' } else {',
|
|
313
|
+
' try {',
|
|
314
|
+
` var page = doc.pages[${pageIndex}];`,
|
|
315
|
+
' if (app.layoutWindows.length > 0) {',
|
|
316
|
+
' var win = app.layoutWindows[0];',
|
|
317
|
+
' try { win.activePage = page; } catch (e) {}',
|
|
318
|
+
` try { win.zoomPercentage = ${zoomLevel}; } catch (e) {}`,
|
|
319
|
+
' } else {',
|
|
320
|
+
' try { page.select(); } catch (e) {}',
|
|
321
|
+
' }',
|
|
322
|
+
` "Zoomed to page ${pageIndex} at ${zoomLevel}%";`,
|
|
323
|
+
' } catch (error) {',
|
|
324
|
+
' "Error zooming to page: " + error.message;',
|
|
325
|
+
' }',
|
|
326
|
+
' }',
|
|
327
|
+
'}'
|
|
328
|
+
].join('\n');
|
|
329
|
+
|
|
330
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
331
|
+
return formatResponse(result, "Zoom to Page");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Perform data merge operation
|
|
336
|
+
*/
|
|
337
|
+
static async dataMerge(args) {
|
|
338
|
+
const { dataSource, targetPage = 0, createNewPages = false, removeUnusedPages = false } = args;
|
|
339
|
+
const escapedDataSource = escapeFilePathForJsx(dataSource);
|
|
340
|
+
|
|
341
|
+
const script = [
|
|
342
|
+
'if (app.documents.length === 0) {',
|
|
343
|
+
' "No document open";',
|
|
344
|
+
'} else {',
|
|
345
|
+
' var doc = app.activeDocument;',
|
|
346
|
+
` var dataFile = File("${escapedDataSource}");`,
|
|
347
|
+
'',
|
|
348
|
+
' if (!dataFile.exists) {',
|
|
349
|
+
` "Data source file not found: ${escapedDataSource}";`,
|
|
350
|
+
' } else {',
|
|
351
|
+
' try {',
|
|
352
|
+
` var targetPageObj = doc.pages[${targetPage}];`,
|
|
353
|
+
` doc.dataMerge(dataFile, targetPageObj, ${createNewPages}, ${removeUnusedPages});`,
|
|
354
|
+
' "Data merge completed successfully";',
|
|
355
|
+
' } catch (error) {',
|
|
356
|
+
' "Error performing data merge: " + error.message;',
|
|
357
|
+
' }',
|
|
358
|
+
' }',
|
|
359
|
+
'}'
|
|
360
|
+
].join('\n');
|
|
361
|
+
|
|
362
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
363
|
+
return formatResponse(result, "Data Merge");
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// =================== DOCUMENT ELEMENTS & STYLES ===================
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Get all elements in the document
|
|
370
|
+
*/
|
|
371
|
+
static async getDocumentElements(args) {
|
|
372
|
+
const { elementType = 'all' } = args;
|
|
373
|
+
|
|
374
|
+
const script = [
|
|
375
|
+
'if (app.documents.length === 0) {',
|
|
376
|
+
' "No document open";',
|
|
377
|
+
'} else {',
|
|
378
|
+
' var doc = app.activeDocument;',
|
|
379
|
+
' var result = "Document Elements:\\n";',
|
|
380
|
+
'',
|
|
381
|
+
' if ("' + elementType + '" === "all" || "' + elementType + '" === "text") {',
|
|
382
|
+
' result += "Text Frames: " + doc.textFrames.length + "\\n";',
|
|
383
|
+
' result += "Stories: " + doc.stories.length + "\\n";',
|
|
384
|
+
' }',
|
|
385
|
+
'',
|
|
386
|
+
' if ("' + elementType + '" === "all" || "' + elementType + '" === "graphics") {',
|
|
387
|
+
' result += "Rectangles: " + doc.rectangles.length + "\\n";',
|
|
388
|
+
' result += "Ovals: " + doc.ovals.length + "\\n";',
|
|
389
|
+
' result += "Polygons: " + doc.polygons.length + "\\n";',
|
|
390
|
+
' result += "Graphic Lines: " + doc.graphicLines.length + "\\n";',
|
|
391
|
+
' result += "All Graphics: " + doc.allGraphics.length + "\\n";',
|
|
392
|
+
' }',
|
|
393
|
+
'',
|
|
394
|
+
' if ("' + elementType + '" === "all" || "' + elementType + '" === "tables") {',
|
|
395
|
+
' var tableCount = 0;',
|
|
396
|
+
' for (var i = 0; i < doc.textFrames.length; i++) {',
|
|
397
|
+
' if (doc.textFrames[i].tables.length > 0) {',
|
|
398
|
+
' tableCount += doc.textFrames[i].tables.length;',
|
|
399
|
+
' }',
|
|
400
|
+
' }',
|
|
401
|
+
' result += "Tables: " + tableCount + "\\n";',
|
|
402
|
+
' }',
|
|
403
|
+
'',
|
|
404
|
+
' if ("' + elementType + '" === "all") {',
|
|
405
|
+
' result += "All Page Items: " + doc.allPageItems.length + "\\n";',
|
|
406
|
+
' result += "Groups: " + doc.groups.length + "\\n";',
|
|
407
|
+
' result += "Layers: " + doc.layers.length + "\\n";',
|
|
408
|
+
' }',
|
|
409
|
+
'',
|
|
410
|
+
' result;',
|
|
411
|
+
'}'
|
|
412
|
+
].join('\n');
|
|
413
|
+
|
|
414
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
415
|
+
return formatResponse(result, "Get Document Elements");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Get all styles in the document
|
|
420
|
+
*/
|
|
421
|
+
static async getDocumentStyles(args) {
|
|
422
|
+
const { styleType = 'PARAGRAPH' } = args;
|
|
423
|
+
|
|
424
|
+
const script = [
|
|
425
|
+
'if (app.documents.length === 0) {',
|
|
426
|
+
' "No document open";',
|
|
427
|
+
'} else {',
|
|
428
|
+
' var doc = app.activeDocument;',
|
|
429
|
+
' var result = "Document Styles (' + styleType + '):\\n";',
|
|
430
|
+
'',
|
|
431
|
+
' switch ("' + styleType + '") {',
|
|
432
|
+
' case "PARAGRAPH":',
|
|
433
|
+
' result += "Count: " + doc.paragraphStyles.length + "\\n";',
|
|
434
|
+
' for (var i = 0; i < doc.paragraphStyles.length; i++) {',
|
|
435
|
+
' result += "- " + doc.paragraphStyles[i].name + "\\n";',
|
|
436
|
+
' }',
|
|
437
|
+
' break;',
|
|
438
|
+
' case "CHARACTER":',
|
|
439
|
+
' result += "Count: " + doc.characterStyles.length + "\\n";',
|
|
440
|
+
' for (var i = 0; i < doc.characterStyles.length; i++) {',
|
|
441
|
+
' result += "- " + doc.characterStyles[i].name + "\\n";',
|
|
442
|
+
' }',
|
|
443
|
+
' break;',
|
|
444
|
+
' case "OBJECT":',
|
|
445
|
+
' result += "Count: " + doc.objectStyles.length + "\\n";',
|
|
446
|
+
' for (var i = 0; i < doc.objectStyles.length; i++) {',
|
|
447
|
+
' result += "- " + doc.objectStyles[i].name + "\\n";',
|
|
448
|
+
' }',
|
|
449
|
+
' break;',
|
|
450
|
+
' case "TABLE":',
|
|
451
|
+
' result += "Count: " + doc.tableStyles.length + "\\n";',
|
|
452
|
+
' for (var i = 0; i < doc.tableStyles.length; i++) {',
|
|
453
|
+
' result += "- " + doc.tableStyles[i].name + "\\n";',
|
|
454
|
+
' }',
|
|
455
|
+
' break;',
|
|
456
|
+
' case "CELL":',
|
|
457
|
+
' result += "Count: " + doc.cellStyles.length + "\\n";',
|
|
458
|
+
' for (var i = 0; i < doc.cellStyles.length; i++) {',
|
|
459
|
+
' result += "- " + doc.cellStyles[i].name + "\\n";',
|
|
460
|
+
' }',
|
|
461
|
+
' break;',
|
|
462
|
+
' }',
|
|
463
|
+
'',
|
|
464
|
+
' result;',
|
|
465
|
+
'}'
|
|
466
|
+
].join('\n');
|
|
467
|
+
|
|
468
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
469
|
+
return formatResponse(result, "Get Document Styles");
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Get all colors and swatches in the document
|
|
474
|
+
*/
|
|
475
|
+
static async getDocumentColors(args) {
|
|
476
|
+
const { includeSwatches = true, includeGradients = true, includeTints = true } = args;
|
|
477
|
+
|
|
478
|
+
const script = [
|
|
479
|
+
'if (app.documents.length === 0) {',
|
|
480
|
+
' "No document open";',
|
|
481
|
+
'} else {',
|
|
482
|
+
' var doc = app.activeDocument;',
|
|
483
|
+
' var result = "Document Colors:\\n";',
|
|
484
|
+
'',
|
|
485
|
+
' result += "Colors: " + doc.colors.length + "\\n";',
|
|
486
|
+
' for (var i = 0; i < doc.colors.length; i++) {',
|
|
487
|
+
' result += "- " + doc.colors[i].name + " (" + doc.colors[i].model + ")\\n";',
|
|
488
|
+
' }',
|
|
489
|
+
'',
|
|
490
|
+
' if (' + includeSwatches + ') {',
|
|
491
|
+
' result += "\\nSwatches: " + doc.swatches.length + "\\n";',
|
|
492
|
+
' for (var i = 0; i < doc.swatches.length; i++) {',
|
|
493
|
+
' result += "- " + doc.swatches[i].name + "\\n";',
|
|
494
|
+
' }',
|
|
495
|
+
' }',
|
|
496
|
+
'',
|
|
497
|
+
' if (' + includeGradients + ') {',
|
|
498
|
+
' result += "\\nGradients: " + doc.gradients.length + "\\n";',
|
|
499
|
+
' for (var i = 0; i < doc.gradients.length; i++) {',
|
|
500
|
+
' result += "- " + doc.gradients[i].name + "\\n";',
|
|
501
|
+
' }',
|
|
502
|
+
' }',
|
|
503
|
+
'',
|
|
504
|
+
' if (' + includeTints + ') {',
|
|
505
|
+
' result += "\\nTints: " + doc.tints.length + "\\n";',
|
|
506
|
+
' for (var i = 0; i < doc.tints.length; i++) {',
|
|
507
|
+
' result += "- " + doc.tints[i].name + "\\n";',
|
|
508
|
+
' }',
|
|
509
|
+
' }',
|
|
510
|
+
'',
|
|
511
|
+
' result;',
|
|
512
|
+
'}'
|
|
513
|
+
].join('\n');
|
|
514
|
+
|
|
515
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
516
|
+
return formatResponse(result, "Get Document Colors");
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// =================== DOCUMENT PREFERENCES ===================
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Get document preferences
|
|
523
|
+
*/
|
|
524
|
+
static async getDocumentPreferences(args) {
|
|
525
|
+
const { preferenceType = 'GENERAL' } = args;
|
|
526
|
+
|
|
527
|
+
const script = [
|
|
528
|
+
'if (app.documents.length === 0) {',
|
|
529
|
+
' "No document open";',
|
|
530
|
+
'} else {',
|
|
531
|
+
' var doc = app.activeDocument;',
|
|
532
|
+
' var result = "Document Preferences (' + preferenceType + '):\\n\\n";',
|
|
533
|
+
'',
|
|
534
|
+
' switch ("' + preferenceType + '") {',
|
|
535
|
+
' case "GENERAL":',
|
|
536
|
+
' try {',
|
|
537
|
+
' result += "Page Width: " + doc.documentPreferences.pageWidth + "\\n";',
|
|
538
|
+
' } catch (e) { result += "Page Width: Not available\\n"; }',
|
|
539
|
+
' try {',
|
|
540
|
+
' result += "Page Height: " + doc.documentPreferences.pageHeight + "\\n";',
|
|
541
|
+
' } catch (e) { result += "Page Height: Not available\\n"; }',
|
|
542
|
+
' try {',
|
|
543
|
+
' result += "Facing Pages: " + doc.documentPreferences.facingPages + "\\n";',
|
|
544
|
+
' } catch (e) { result += "Facing Pages: Not available\\n"; }',
|
|
545
|
+
' try {',
|
|
546
|
+
' result += "Page Orientation: " + doc.documentPreferences.pageOrientation + "\\n";',
|
|
547
|
+
' } catch (e) { result += "Page Orientation: Not available\\n"; }',
|
|
548
|
+
' try {',
|
|
549
|
+
' result += "Pages Per Document: " + doc.documentPreferences.pagesPerDocument + "\\n";',
|
|
550
|
+
' } catch (e) { result += "Pages Per Document: Not available\\n"; }',
|
|
551
|
+
' try {',
|
|
552
|
+
' result += "Start Page Number: " + doc.documentPreferences.startPageNumber + "\\n";',
|
|
553
|
+
' } catch (e) { result += "Start Page Number: Not available\\n"; }',
|
|
554
|
+
' try {',
|
|
555
|
+
' result += "Document Bleed Top Offset: " + doc.documentPreferences.documentBleedTopOffset + "\\n";',
|
|
556
|
+
' } catch (e) { result += "Document Bleed Top Offset: Not available\\n"; }',
|
|
557
|
+
' try {',
|
|
558
|
+
' result += "Document Bleed Bottom Offset: " + doc.documentPreferences.documentBleedBottomOffset + "\\n";',
|
|
559
|
+
' } catch (e) { result += "Document Bleed Bottom Offset: Not available\\n"; }',
|
|
560
|
+
' try {',
|
|
561
|
+
' result += "Document Bleed Inside Or Left Offset: " + doc.documentPreferences.documentBleedInsideOrLeftOffset + "\\n";',
|
|
562
|
+
' } catch (e) { result += "Document Bleed Inside Or Left Offset: Not available\\n"; }',
|
|
563
|
+
' try {',
|
|
564
|
+
' result += "Document Bleed Outside Or Right Offset: " + doc.documentPreferences.documentBleedOutsideOrRightOffset + "\\n";',
|
|
565
|
+
' } catch (e) { result += "Document Bleed Outside Or Right Offset: Not available\\n"; }',
|
|
566
|
+
' try {',
|
|
567
|
+
' result += "Document Slug Top Offset: " + doc.documentPreferences.documentSlugTopOffset + "\\n";',
|
|
568
|
+
' } catch (e) { result += "Document Slug Top Offset: Not available\\n"; }',
|
|
569
|
+
' try {',
|
|
570
|
+
' result += "Document Slug Bottom Offset: " + doc.documentPreferences.documentSlugBottomOffset + "\\n";',
|
|
571
|
+
' } catch (e) { result += "Document Slug Bottom Offset: Not available\\n"; }',
|
|
572
|
+
' try {',
|
|
573
|
+
' result += "Document Slug Inside Or Left Offset: " + doc.documentPreferences.documentSlugInsideOrLeftOffset + "\\n";',
|
|
574
|
+
' } catch (e) { result += "Document Slug Inside Or Left Offset: Not available\\n"; }',
|
|
575
|
+
' try {',
|
|
576
|
+
' result += "Document Slug Outside Or Right Offset: " + doc.documentPreferences.documentSlugOutsideOrRightOffset + "\\n";',
|
|
577
|
+
' } catch (e) { result += "Document Slug Outside Or Right Offset: Not available\\n"; }',
|
|
578
|
+
' break;',
|
|
579
|
+
' case "GRID":',
|
|
580
|
+
' try {',
|
|
581
|
+
' result += "Document Grid Color: " + doc.gridPreferences.documentGridColor + "\\n";',
|
|
582
|
+
' } catch (e) { result += "Document Grid Color: Not available\\n"; }',
|
|
583
|
+
' try {',
|
|
584
|
+
' result += "Document Grid Increment: " + doc.gridPreferences.documentGridIncrement + "\\n";',
|
|
585
|
+
' } catch (e) { result += "Document Grid Increment: Not available\\n"; }',
|
|
586
|
+
' try {',
|
|
587
|
+
' result += "Document Grid Subdivision: " + doc.gridPreferences.documentGridSubdivision + "\\n";',
|
|
588
|
+
' } catch (e) { result += "Document Grid Subdivision: Not available\\n"; }',
|
|
589
|
+
' try {',
|
|
590
|
+
' result += "Grid View Threshold: " + doc.gridPreferences.gridViewThreshold + "\\n";',
|
|
591
|
+
' } catch (e) { result += "Grid View Threshold: Not available\\n"; }',
|
|
592
|
+
' try {',
|
|
593
|
+
' result += "Baseline Grid Color: " + doc.gridPreferences.baselineGridColor + "\\n";',
|
|
594
|
+
' } catch (e) { result += "Baseline Grid Color: Not available\\n"; }',
|
|
595
|
+
' try {',
|
|
596
|
+
' result += "Baseline Grid Increment: " + doc.gridPreferences.baselineGridIncrement + "\\n";',
|
|
597
|
+
' } catch (e) { result += "Baseline Grid Increment: Not available\\n"; }',
|
|
598
|
+
' try {',
|
|
599
|
+
' result += "Baseline Grid Offset: " + doc.gridPreferences.baselineGridOffset + "\\n";',
|
|
600
|
+
' } catch (e) { result += "Baseline Grid Offset: Not available\\n"; }',
|
|
601
|
+
' try {',
|
|
602
|
+
' result += "Baseline Grid View Threshold: " + doc.gridPreferences.baselineGridViewThreshold + "\\n";',
|
|
603
|
+
' } catch (e) { result += "Baseline Grid View Threshold: Not available\\n"; }',
|
|
604
|
+
' try {',
|
|
605
|
+
' result += "Grid Alignment: " + doc.gridPreferences.gridAlignment + "\\n";',
|
|
606
|
+
' } catch (e) { result += "Grid Alignment: Not available\\n"; }',
|
|
607
|
+
' break;',
|
|
608
|
+
' case "GUIDES":',
|
|
609
|
+
' try {',
|
|
610
|
+
' result += "Guides Locked: " + doc.guidePreferences.guidesLocked + "\\n";',
|
|
611
|
+
' } catch (e) { result += "Guides Locked: Not available\\n"; }',
|
|
612
|
+
' try {',
|
|
613
|
+
' result += "Guides In Back: " + doc.guidePreferences.guidesInBack + "\\n";',
|
|
614
|
+
' } catch (e) { result += "Guides In Back: Not available\\n"; }',
|
|
615
|
+
' try {',
|
|
616
|
+
' result += "Guides Snap To Zone: " + doc.guidePreferences.guidesSnapToZone + "\\n";',
|
|
617
|
+
' } catch (e) { result += "Guides Snap To Zone: Not available\\n"; }',
|
|
618
|
+
' try {',
|
|
619
|
+
' result += "Guides View Threshold: " + doc.guidePreferences.guidesViewThreshold + "\\n";',
|
|
620
|
+
' } catch (e) { result += "Guides View Threshold: Not available\\n"; }',
|
|
621
|
+
' break;',
|
|
622
|
+
' case "TEXT":',
|
|
623
|
+
' try {',
|
|
624
|
+
' result += "Typographers Quotes: " + doc.textPreferences.typographersQuotes + "\\n";',
|
|
625
|
+
' } catch (e) { result += "Typographers Quotes: Not available\\n"; }',
|
|
626
|
+
' try {',
|
|
627
|
+
' result += "Use Typographers Quotes: " + doc.textPreferences.useTypographersQuotes + "\\n";',
|
|
628
|
+
' } catch (e) { result += "Use Typographers Quotes: Not available\\n"; }',
|
|
629
|
+
' try {',
|
|
630
|
+
' result += "Highlight Substituted Fonts: " + doc.textPreferences.highlightSubstitutedFonts + "\\n";',
|
|
631
|
+
' } catch (e) { result += "Highlight Substituted Fonts: Not available\\n"; }',
|
|
632
|
+
' try {',
|
|
633
|
+
' result += "Highlight Substituted Glyphs: " + doc.textPreferences.highlightSubstitutedGlyphs + "\\n";',
|
|
634
|
+
' } catch (e) { result += "Highlight Substituted Glyphs: Not available\\n"; }',
|
|
635
|
+
' try {',
|
|
636
|
+
' result += "Highlight Keeps Violations: " + doc.textPreferences.highlightKeepsViolations + "\\n";',
|
|
637
|
+
' } catch (e) { result += "Highlight Keeps Violations: Not available\\n"; }',
|
|
638
|
+
' try {',
|
|
639
|
+
' result += "Highlight H&J Violations: " + doc.textPreferences.highlightHjViolations + "\\n";',
|
|
640
|
+
' } catch (e) { result += "Highlight H&J Violations: Not available\\n"; }',
|
|
641
|
+
' try {',
|
|
642
|
+
' result += "Highlight Custom Spacing: " + doc.textPreferences.highlightCustomSpacing + "\\n";',
|
|
643
|
+
' } catch (e) { result += "Highlight Custom Spacing: Not available\\n"; }',
|
|
644
|
+
' try {',
|
|
645
|
+
' result += "Highlight Substituted Lines: " + doc.textPreferences.highlightSubstitutedLines + "\\n";',
|
|
646
|
+
' } catch (e) { result += "Highlight Substituted Lines: Not available\\n"; }',
|
|
647
|
+
' break;',
|
|
648
|
+
' case "MARGINS":',
|
|
649
|
+
' try {',
|
|
650
|
+
' result += "Margin Top: " + doc.marginPreferences.top + "\\n";',
|
|
651
|
+
' } catch (e) { result += "Margin Top: Not available\\n"; }',
|
|
652
|
+
' try {',
|
|
653
|
+
' result += "Margin Bottom: " + doc.marginPreferences.bottom + "\\n";',
|
|
654
|
+
' } catch (e) { result += "Margin Bottom: Not available\\n"; }',
|
|
655
|
+
' try {',
|
|
656
|
+
' result += "Margin Left: " + doc.marginPreferences.left + "\\n";',
|
|
657
|
+
' } catch (e) { result += "Margin Left: Not available\\n"; }',
|
|
658
|
+
' try {',
|
|
659
|
+
' result += "Margin Right: " + doc.marginPreferences.right + "\\n";',
|
|
660
|
+
' } catch (e) { result += "Margin Right: Not available\\n"; }',
|
|
661
|
+
' try {',
|
|
662
|
+
' result += "Margin Column Count: " + doc.marginPreferences.columnCount + "\\n";',
|
|
663
|
+
' } catch (e) { result += "Margin Column Count: Not available\\n"; }',
|
|
664
|
+
' try {',
|
|
665
|
+
' result += "Margin Column Gutter: " + doc.marginPreferences.columnGutter + "\\n";',
|
|
666
|
+
' } catch (e) { result += "Margin Column Gutter: Not available\\n"; }',
|
|
667
|
+
' break;',
|
|
668
|
+
' default:',
|
|
669
|
+
' result += "Unknown preference type: " + preferenceType + "\\n";',
|
|
670
|
+
' result += "Available types: GENERAL, GRID, GUIDES, TEXT, MARGINS\\n";',
|
|
671
|
+
' }',
|
|
672
|
+
'',
|
|
673
|
+
' result;',
|
|
674
|
+
'}'
|
|
675
|
+
].join('\n');
|
|
676
|
+
|
|
677
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
678
|
+
return formatResponse(result, "Get Document Preferences");
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Set document preferences
|
|
683
|
+
*/
|
|
684
|
+
static async setDocumentPreferences(args) {
|
|
685
|
+
const { preferenceType, preferences = {} } = args;
|
|
686
|
+
|
|
687
|
+
const updates = [];
|
|
688
|
+
|
|
689
|
+
if (preferenceType === 'GENERAL') {
|
|
690
|
+
if (preferences.pageWidth !== undefined) updates.push(`try { doc.documentPreferences.pageWidth = UnitValue("${preferences.pageWidth}mm"); updatedCount++; } catch (e) {}`);
|
|
691
|
+
if (preferences.pageHeight !== undefined) updates.push(`try { doc.documentPreferences.pageHeight = UnitValue("${preferences.pageHeight}mm"); updatedCount++; } catch (e) {}`);
|
|
692
|
+
if (preferences.facingPages !== undefined) updates.push(`try { doc.documentPreferences.facingPages = ${preferences.facingPages}; updatedCount++; } catch (e) {}`);
|
|
693
|
+
if (preferences.pagesPerDocument !== undefined) updates.push(`try { doc.documentPreferences.pagesPerDocument = ${preferences.pagesPerDocument}; updatedCount++; } catch (e) {}`);
|
|
694
|
+
if (preferences.startPageNumber !== undefined) updates.push(`try { doc.documentPreferences.startPageNumber = ${preferences.startPageNumber}; updatedCount++; } catch (e) {}`);
|
|
695
|
+
if (preferences.documentBleedTopOffset !== undefined) updates.push(`try { doc.documentPreferences.documentBleedTopOffset = UnitValue("${preferences.documentBleedTopOffset}mm"); updatedCount++; } catch (e) {}`);
|
|
696
|
+
if (preferences.documentBleedBottomOffset !== undefined) updates.push(`try { doc.documentPreferences.documentBleedBottomOffset = UnitValue("${preferences.documentBleedBottomOffset}mm"); updatedCount++; } catch (e) {}`);
|
|
697
|
+
if (preferences.documentBleedInsideOrLeftOffset !== undefined) updates.push(`try { doc.documentPreferences.documentBleedInsideOrLeftOffset = UnitValue("${preferences.documentBleedInsideOrLeftOffset}mm"); updatedCount++; } catch (e) {}`);
|
|
698
|
+
if (preferences.documentBleedOutsideOrRightOffset !== undefined) updates.push(`try { doc.documentPreferences.documentBleedOutsideOrRightOffset = UnitValue("${preferences.documentBleedOutsideOrRightOffset}mm"); updatedCount++; } catch (e) {}`);
|
|
699
|
+
} else if (preferenceType === 'GRID') {
|
|
700
|
+
if (preferences.documentGridColor !== undefined) updates.push(`try { doc.gridPreferences.documentGridColor = "${escapeJsxString(preferences.documentGridColor)}"; updatedCount++; } catch (e) {}`);
|
|
701
|
+
if (preferences.documentGridIncrement !== undefined) updates.push(`try { doc.gridPreferences.documentGridIncrement = UnitValue("${preferences.documentGridIncrement}mm"); updatedCount++; } catch (e) {}`);
|
|
702
|
+
if (preferences.documentGridSubdivision !== undefined) updates.push(`try { doc.gridPreferences.documentGridSubdivision = ${preferences.documentGridSubdivision}; updatedCount++; } catch (e) {}`);
|
|
703
|
+
if (preferences.gridViewThreshold !== undefined) updates.push(`try { doc.gridPreferences.gridViewThreshold = ${preferences.gridViewThreshold}; updatedCount++; } catch (e) {}`);
|
|
704
|
+
if (preferences.baselineGridColor !== undefined) updates.push(`try { doc.gridPreferences.baselineGridColor = "${escapeJsxString(preferences.baselineGridColor)}"; updatedCount++; } catch (e) {}`);
|
|
705
|
+
if (preferences.baselineGridIncrement !== undefined) updates.push(`try { doc.gridPreferences.baselineGridIncrement = UnitValue("${preferences.baselineGridIncrement}mm"); updatedCount++; } catch (e) {}`);
|
|
706
|
+
if (preferences.baselineGridOffset !== undefined) updates.push(`try { doc.gridPreferences.baselineGridOffset = UnitValue("${preferences.baselineGridOffset}mm"); updatedCount++; } catch (e) {}`);
|
|
707
|
+
if (preferences.baselineGridViewThreshold !== undefined) updates.push(`try { doc.gridPreferences.baselineGridViewThreshold = ${preferences.baselineGridViewThreshold}; updatedCount++; } catch (e) {}`);
|
|
708
|
+
if (preferences.gridAlignment !== undefined) updates.push(`try { doc.gridPreferences.gridAlignment = "${escapeJsxString(preferences.gridAlignment)}"; updatedCount++; } catch (e) {}`);
|
|
709
|
+
} else if (preferenceType === 'GUIDES') {
|
|
710
|
+
if (preferences.guidesLocked !== undefined) updates.push(`try { doc.guidePreferences.guidesLocked = ${preferences.guidesLocked}; updatedCount++; } catch (e) {}`);
|
|
711
|
+
if (preferences.guidesInBack !== undefined) updates.push(`try { doc.guidePreferences.guidesInBack = ${preferences.guidesInBack}; updatedCount++; } catch (e) {}`);
|
|
712
|
+
if (preferences.guidesSnapToZone !== undefined) updates.push(`try { doc.guidePreferences.guidesSnapToZone = ${preferences.guidesSnapToZone}; updatedCount++; } catch (e) {}`);
|
|
713
|
+
if (preferences.guidesViewThreshold !== undefined) updates.push(`try { doc.guidePreferences.guidesViewThreshold = ${preferences.guidesViewThreshold}; updatedCount++; } catch (e) {}`);
|
|
714
|
+
} else if (preferenceType === 'TEXT') {
|
|
715
|
+
if (preferences.typographersQuotes !== undefined) updates.push(`try { doc.textPreferences.typographersQuotes = ${preferences.typographersQuotes}; updatedCount++; } catch (e) {}`);
|
|
716
|
+
if (preferences.useTypographersQuotes !== undefined) updates.push(`try { doc.textPreferences.useTypographersQuotes = ${preferences.useTypographersQuotes}; updatedCount++; } catch (e) {}`);
|
|
717
|
+
if (preferences.highlightSubstitutedFonts !== undefined) updates.push(`try { doc.textPreferences.highlightSubstitutedFonts = ${preferences.highlightSubstitutedFonts}; updatedCount++; } catch (e) {}`);
|
|
718
|
+
if (preferences.highlightSubstitutedGlyphs !== undefined) updates.push(`try { doc.textPreferences.highlightSubstitutedGlyphs = ${preferences.highlightSubstitutedGlyphs}; updatedCount++; } catch (e) {}`);
|
|
719
|
+
if (preferences.highlightKeepsViolations !== undefined) updates.push(`try { doc.textPreferences.highlightKeepsViolations = ${preferences.highlightKeepsViolations}; updatedCount++; } catch (e) {}`);
|
|
720
|
+
if (preferences.highlightHjViolations !== undefined) updates.push(`try { doc.textPreferences.highlightHjViolations = ${preferences.highlightHjViolations}; updatedCount++; } catch (e) {}`);
|
|
721
|
+
if (preferences.highlightCustomSpacing !== undefined) updates.push(`try { doc.textPreferences.highlightCustomSpacing = ${preferences.highlightCustomSpacing}; updatedCount++; } catch (e) {}`);
|
|
722
|
+
if (preferences.highlightSubstitutedLines !== undefined) updates.push(`try { doc.textPreferences.highlightSubstitutedLines = ${preferences.highlightSubstitutedLines}; updatedCount++; } catch (e) {}`);
|
|
723
|
+
} else if (preferenceType === 'MARGINS') {
|
|
724
|
+
if (preferences.marginTop !== undefined) updates.push(`try { doc.marginPreferences.top = UnitValue("${preferences.marginTop}mm"); updatedCount++; } catch (e) {}`);
|
|
725
|
+
if (preferences.marginBottom !== undefined) updates.push(`try { doc.marginPreferences.bottom = UnitValue("${preferences.marginBottom}mm"); updatedCount++; } catch (e) {}`);
|
|
726
|
+
if (preferences.marginLeft !== undefined) updates.push(`try { doc.marginPreferences.left = UnitValue("${preferences.marginLeft}mm"); updatedCount++; } catch (e) {}`);
|
|
727
|
+
if (preferences.marginRight !== undefined) updates.push(`try { doc.marginPreferences.right = UnitValue("${preferences.marginRight}mm"); updatedCount++; } catch (e) {}`);
|
|
728
|
+
if (preferences.columnCount !== undefined) updates.push(`try { doc.marginPreferences.columnCount = ${preferences.columnCount}; updatedCount++; } catch (e) {}`);
|
|
729
|
+
if (preferences.columnGutter !== undefined) updates.push(`try { doc.marginPreferences.columnGutter = UnitValue("${preferences.columnGutter}mm"); updatedCount++; } catch (e) {}`);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
const script = [
|
|
733
|
+
'if (app.documents.length === 0) {',
|
|
734
|
+
' "No document open";',
|
|
735
|
+
'} else {',
|
|
736
|
+
' var doc = app.activeDocument;',
|
|
737
|
+
' var updatedCount = 0;',
|
|
738
|
+
' try {',
|
|
739
|
+
...(updates.length ? updates : [' // No preferences provided for this type']),
|
|
740
|
+
' "Document preferences updated successfully. " + updatedCount + " properties updated.";',
|
|
741
|
+
' } catch (error) {',
|
|
742
|
+
' "Error updating document preferences: " + error.message;',
|
|
743
|
+
' }',
|
|
744
|
+
'}'
|
|
745
|
+
].join('\n');
|
|
746
|
+
|
|
747
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
748
|
+
return formatResponse(result, "Set Document Preferences");
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// =================== DOCUMENT STORIES & TEXT ===================
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Get all stories in the document
|
|
755
|
+
*/
|
|
756
|
+
static async getDocumentStories(args) {
|
|
757
|
+
const { includeOverset = true, includeHidden = false } = args;
|
|
758
|
+
|
|
759
|
+
const script = [
|
|
760
|
+
'if (app.documents.length === 0) {',
|
|
761
|
+
' "No document open";',
|
|
762
|
+
'} else {',
|
|
763
|
+
' var doc = app.activeDocument;',
|
|
764
|
+
' var result = "Document Stories:\\n";',
|
|
765
|
+
' var storyCount = 0;',
|
|
766
|
+
'',
|
|
767
|
+
' for (var i = 0; i < doc.stories.length; i++) {',
|
|
768
|
+
' var story = doc.stories[i];',
|
|
769
|
+
' var isHidden = false;',
|
|
770
|
+
' var isOverset = false;',
|
|
771
|
+
' var storyName = "";',
|
|
772
|
+
' try { isHidden = story.hidden; } catch (hiddenError) { isHidden = false; }',
|
|
773
|
+
' try { isOverset = story.overset; } catch (oversetError) { isOverset = false; }',
|
|
774
|
+
' try { storyName = story.name; } catch (nameError) { storyName = "Story " + (i + 1); }',
|
|
775
|
+
' if (' + includeHidden + ' || !isHidden) {',
|
|
776
|
+
' storyCount++;',
|
|
777
|
+
' result += "Story " + storyCount + ": " + storyName + "\\n";',
|
|
778
|
+
' result += " Contents: " + story.contents.substring(0, 50) + "...\\n";',
|
|
779
|
+
' result += " Overset: " + isOverset + "\\n";',
|
|
780
|
+
' result += " Hidden: " + isHidden + "\\n\\n";',
|
|
781
|
+
' }',
|
|
782
|
+
' }',
|
|
783
|
+
'',
|
|
784
|
+
' result += "Total Stories: " + storyCount;',
|
|
785
|
+
' result;',
|
|
786
|
+
'}'
|
|
787
|
+
].join('\n');
|
|
788
|
+
|
|
789
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
790
|
+
return formatResponse(result, "Get Document Stories");
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Find text across the entire document
|
|
795
|
+
*/
|
|
796
|
+
static async findTextInDocument(args) {
|
|
797
|
+
const { searchText, replaceText, caseSensitive = false, wholeWord = false, useRegex = false } = args;
|
|
798
|
+
const escapedSearchText = escapeJsxString(searchText);
|
|
799
|
+
const escapedReplaceText = replaceText ? escapeJsxString(replaceText) : '';
|
|
800
|
+
|
|
801
|
+
const script = [
|
|
802
|
+
'if (app.documents.length === 0) {',
|
|
803
|
+
' "No document open";',
|
|
804
|
+
'} else {',
|
|
805
|
+
' var doc = app.activeDocument;',
|
|
806
|
+
' var foundCount = 0;',
|
|
807
|
+
'',
|
|
808
|
+
' try {',
|
|
809
|
+
' app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;',
|
|
810
|
+
' app.findTextPreferences.findWhat = "' + escapedSearchText + '";',
|
|
811
|
+
' try { app.findTextPreferences.caseSensitive = ' + caseSensitive + '; } catch (caseError) {}',
|
|
812
|
+
' try { app.findTextPreferences.wholeWord = ' + wholeWord + '; } catch (wordError) {}',
|
|
813
|
+
'',
|
|
814
|
+
' if ("' + escapedReplaceText + '") {',
|
|
815
|
+
' app.changeTextPreferences.changeTo = "' + escapedReplaceText + '";',
|
|
816
|
+
' var found = doc.changeText();',
|
|
817
|
+
' foundCount = found.length;',
|
|
818
|
+
' "Found and replaced " + foundCount + " instances of \\"" + "' + escapedSearchText + '" + "\\"";',
|
|
819
|
+
' } else {',
|
|
820
|
+
' var found = doc.findText();',
|
|
821
|
+
' foundCount = found.length;',
|
|
822
|
+
' "Found " + foundCount + " instances of \\"" + "' + escapedSearchText + '" + "\\"";',
|
|
823
|
+
' }',
|
|
824
|
+
' } catch (error) {',
|
|
825
|
+
' "Error during find/replace: " + error.message;',
|
|
826
|
+
' }',
|
|
827
|
+
'}'
|
|
828
|
+
].join('\n');
|
|
829
|
+
|
|
830
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
831
|
+
return formatResponse(result, "Find Text in Document");
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// =================== DOCUMENT LAYERS & ORGANIZATION ===================
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Get all layers in the document
|
|
838
|
+
*/
|
|
839
|
+
static async getDocumentLayers(args) {
|
|
840
|
+
const { includeHidden = true, includeLocked = true } = args;
|
|
841
|
+
|
|
842
|
+
const script = [
|
|
843
|
+
'if (app.documents.length === 0) {',
|
|
844
|
+
' "No document open";',
|
|
845
|
+
'} else {',
|
|
846
|
+
' var doc = app.activeDocument;',
|
|
847
|
+
' var result = "Document Layers:\\n";',
|
|
848
|
+
' var layerCount = 0;',
|
|
849
|
+
'',
|
|
850
|
+
' for (var i = 0; i < doc.layers.length; i++) {',
|
|
851
|
+
' var layer = doc.layers[i];',
|
|
852
|
+
' if ((' + includeHidden + ' || !layer.visible) && (' + includeLocked + ' || !layer.locked)) {',
|
|
853
|
+
' layerCount++;',
|
|
854
|
+
' result += "Layer " + layerCount + ": " + layer.name + "\\n";',
|
|
855
|
+
' result += " Visible: " + layer.visible + "\\n";',
|
|
856
|
+
' result += " Locked: " + layer.locked + "\\n";',
|
|
857
|
+
' result += " Page Items: " + layer.pageItems.length + "\\n\\n";',
|
|
858
|
+
' }',
|
|
859
|
+
' }',
|
|
860
|
+
'',
|
|
861
|
+
' result += "Total Layers: " + layerCount;',
|
|
862
|
+
' result;',
|
|
863
|
+
'}'
|
|
864
|
+
].join('\n');
|
|
865
|
+
|
|
866
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
867
|
+
return formatResponse(result, "Get Document Layers");
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Organize and clean up document layers
|
|
872
|
+
*/
|
|
873
|
+
static async organizeDocumentLayers(args) {
|
|
874
|
+
const { deleteEmptyLayers = false, mergeSimilarLayers = false, sortLayers = false } = args;
|
|
875
|
+
|
|
876
|
+
const script = [
|
|
877
|
+
'if (app.documents.length === 0) {',
|
|
878
|
+
' "No document open";',
|
|
879
|
+
'} else {',
|
|
880
|
+
' var doc = app.activeDocument;',
|
|
881
|
+
' var actions = [];',
|
|
882
|
+
'',
|
|
883
|
+
' try {',
|
|
884
|
+
' if (' + deleteEmptyLayers + ') {',
|
|
885
|
+
' for (var i = doc.layers.length - 1; i >= 0; i--) {',
|
|
886
|
+
' if (doc.layers[i].pageItems.length === 0) {',
|
|
887
|
+
' doc.layers[i].remove();',
|
|
888
|
+
' actions.push("Deleted empty layer: " + doc.layers[i].name);',
|
|
889
|
+
' }',
|
|
890
|
+
' }',
|
|
891
|
+
' }',
|
|
892
|
+
'',
|
|
893
|
+
' if (' + sortLayers + ') {',
|
|
894
|
+
' // Note: Layer sorting would require more complex logic',
|
|
895
|
+
' actions.push("Layer sorting not implemented in this version");',
|
|
896
|
+
' }',
|
|
897
|
+
'',
|
|
898
|
+
' "Layer organization completed. Actions: " + actions.join(", ");',
|
|
899
|
+
' } catch (error) {',
|
|
900
|
+
' "Error organizing layers: " + error.message;',
|
|
901
|
+
' }',
|
|
902
|
+
'}'
|
|
903
|
+
].join('\n');
|
|
904
|
+
|
|
905
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
906
|
+
return formatResponse(result, "Organize Document Layers");
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// =================== DOCUMENT HYPERLINKS & INTERACTIVITY ===================
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Get all hyperlinks in the document
|
|
913
|
+
*/
|
|
914
|
+
static async getDocumentHyperlinks(args) {
|
|
915
|
+
const { includeDestinations = true, includeSources = true } = args;
|
|
916
|
+
|
|
917
|
+
const script = [
|
|
918
|
+
'if (app.documents.length === 0) {',
|
|
919
|
+
' "No document open";',
|
|
920
|
+
'} else {',
|
|
921
|
+
' var doc = app.activeDocument;',
|
|
922
|
+
' var result = "Document Hyperlinks:\\n";',
|
|
923
|
+
'',
|
|
924
|
+
' for (var i = 0; i < doc.hyperlinks.length; i++) {',
|
|
925
|
+
' var link = doc.hyperlinks[i];',
|
|
926
|
+
' result += "Hyperlink " + (i + 1) + ": " + link.name + "\\n";',
|
|
927
|
+
' result += " Source: " + link.source.name + "\\n";',
|
|
928
|
+
' result += " Destination: " + link.destination.name + "\\n\\n";',
|
|
929
|
+
' }',
|
|
930
|
+
'',
|
|
931
|
+
' result += "Total Hyperlinks: " + doc.hyperlinks.length;',
|
|
932
|
+
' result;',
|
|
933
|
+
'}'
|
|
934
|
+
].join('\n');
|
|
935
|
+
|
|
936
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
937
|
+
return formatResponse(result, "Get Document Hyperlinks");
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Create a hyperlink in the document
|
|
942
|
+
*/
|
|
943
|
+
static async createDocumentHyperlink(args) {
|
|
944
|
+
const { sourceText, destination, linkType = 'URL', pageIndex } = args;
|
|
945
|
+
const escapedSourceText = escapeJsxString(sourceText);
|
|
946
|
+
const escapedDestination = escapeJsxString(destination);
|
|
947
|
+
|
|
948
|
+
const script = [
|
|
949
|
+
'if (app.documents.length === 0) {',
|
|
950
|
+
' "No document open";',
|
|
951
|
+
'} else {',
|
|
952
|
+
' var doc = app.activeDocument;',
|
|
953
|
+
' try {',
|
|
954
|
+
' app.findTextPreferences = NothingEnum.NOTHING;',
|
|
955
|
+
` app.findTextPreferences.findWhat = "${escapedSourceText}";`,
|
|
956
|
+
' var found = doc.findText();',
|
|
957
|
+
' app.findTextPreferences = NothingEnum.NOTHING;',
|
|
958
|
+
' if (!found || found.length === 0) {',
|
|
959
|
+
` throw new Error("Source text not found: ${escapedSourceText}");`,
|
|
960
|
+
' }',
|
|
961
|
+
` var urlDestination = doc.hyperlinkURLDestinations.add("${escapedDestination}");`,
|
|
962
|
+
' var textSource = doc.hyperlinkTextSources.add(found[0]);',
|
|
963
|
+
' var hyperlink = doc.hyperlinks.add(textSource, urlDestination);',
|
|
964
|
+
' hyperlink.name = "Link to ' + escapedDestination + '";',
|
|
965
|
+
' "Hyperlink created successfully: " + hyperlink.name;',
|
|
966
|
+
' } catch (error) {',
|
|
967
|
+
' "Error creating hyperlink: " + error.message;',
|
|
968
|
+
' }',
|
|
969
|
+
'}'
|
|
970
|
+
].join('\n');
|
|
971
|
+
|
|
972
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
973
|
+
return formatResponse(result, "Create Document Hyperlink");
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// =================== DOCUMENT SECTIONS & NUMBERING ===================
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Get all sections in the document
|
|
980
|
+
*/
|
|
981
|
+
static async getDocumentSections() {
|
|
982
|
+
const script = [
|
|
983
|
+
'if (app.documents.length === 0) {',
|
|
984
|
+
' "No document open";',
|
|
985
|
+
'} else {',
|
|
986
|
+
' var doc = app.activeDocument;',
|
|
987
|
+
' var result = "Document Sections:\\n";',
|
|
988
|
+
'',
|
|
989
|
+
' for (var i = 0; i < doc.sections.length; i++) {',
|
|
990
|
+
' var section = doc.sections[i];',
|
|
991
|
+
' result += "Section " + (i + 1) + ": " + section.name + "\\n";',
|
|
992
|
+
' result += " Prefix: " + section.sectionPrefix + "\\n\\n";',
|
|
993
|
+
' }',
|
|
994
|
+
'',
|
|
995
|
+
' result += "Total Sections: " + doc.sections.length;',
|
|
996
|
+
' result;',
|
|
997
|
+
'}'
|
|
998
|
+
].join('\n');
|
|
999
|
+
|
|
1000
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1001
|
+
return formatResponse(result, "Get Document Sections");
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Create a new section in the document
|
|
1006
|
+
*/
|
|
1007
|
+
static async createDocumentSection(args) {
|
|
1008
|
+
const { startPage, sectionPrefix, startNumber = 1, numberingStyle = 'ARABIC' } = args;
|
|
1009
|
+
const escapedSectionPrefix = sectionPrefix ? escapeJsxString(sectionPrefix) : '';
|
|
1010
|
+
const normalizedNumberingStyle = typeof numberingStyle === 'string' ? numberingStyle.trim().toUpperCase() : 'ARABIC';
|
|
1011
|
+
const numberingStyleLiteral = /^[A-Z_]+$/.test(normalizedNumberingStyle)
|
|
1012
|
+
? `PageNumberStyle.${normalizedNumberingStyle}`
|
|
1013
|
+
: 'PageNumberStyle.ARABIC';
|
|
1014
|
+
|
|
1015
|
+
const script = [
|
|
1016
|
+
'if (app.documents.length === 0) {',
|
|
1017
|
+
' "No document open";',
|
|
1018
|
+
'} else {',
|
|
1019
|
+
' var doc = app.activeDocument;',
|
|
1020
|
+
' try {',
|
|
1021
|
+
` var page = doc.pages[${startPage}];`,
|
|
1022
|
+
' var section = doc.sections.add(page);',
|
|
1023
|
+
' if ("' + escapedSectionPrefix + '") section.sectionPrefix = "' + escapedSectionPrefix + '";',
|
|
1024
|
+
` try { section.pageNumberingStyle = ${numberingStyleLiteral}; } catch (styleError) {}`,
|
|
1025
|
+
` try { section.pageNumberStart = ${startNumber}; } catch (startError) {}`,
|
|
1026
|
+
' "Section created successfully on page " + page.name;',
|
|
1027
|
+
' } catch (error) {',
|
|
1028
|
+
' "Error creating section: " + error.message;',
|
|
1029
|
+
' }',
|
|
1030
|
+
'}'
|
|
1031
|
+
].join('\n');
|
|
1032
|
+
|
|
1033
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1034
|
+
return formatResponse(result, "Create Document Section");
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// =================== DOCUMENT XML & STRUCTURE ===================
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* Get XML structure of the document
|
|
1041
|
+
*/
|
|
1042
|
+
static async getDocumentXmlStructure(args) {
|
|
1043
|
+
const { includeTags = true, includeElements = true } = args;
|
|
1044
|
+
|
|
1045
|
+
const script = [
|
|
1046
|
+
'if (app.documents.length === 0) {',
|
|
1047
|
+
' "No document open";',
|
|
1048
|
+
'} else {',
|
|
1049
|
+
' var doc = app.activeDocument;',
|
|
1050
|
+
' var result = "Document XML Structure:\\n";',
|
|
1051
|
+
'',
|
|
1052
|
+
' if (' + includeTags + ') {',
|
|
1053
|
+
' result += "XML Tags: " + doc.xmlTags.length + "\\n";',
|
|
1054
|
+
' for (var i = 0; i < doc.xmlTags.length; i++) {',
|
|
1055
|
+
' result += "- " + doc.xmlTags[i].name + "\\n";',
|
|
1056
|
+
' }',
|
|
1057
|
+
' result += "\\n";',
|
|
1058
|
+
' }',
|
|
1059
|
+
'',
|
|
1060
|
+
' if (' + includeElements + ') {',
|
|
1061
|
+
' result += "XML Elements: " + doc.xmlElements.length + "\\n";',
|
|
1062
|
+
' for (var i = 0; i < doc.xmlElements.length; i++) {',
|
|
1063
|
+
' result += "- Element " + (i + 1) + "\\n";',
|
|
1064
|
+
' }',
|
|
1065
|
+
' }',
|
|
1066
|
+
'',
|
|
1067
|
+
' result;',
|
|
1068
|
+
'}'
|
|
1069
|
+
].join('\n');
|
|
1070
|
+
|
|
1071
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1072
|
+
return formatResponse(result, "Get Document XML Structure");
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* Export document as XML
|
|
1077
|
+
*/
|
|
1078
|
+
static async exportDocumentXml(args) {
|
|
1079
|
+
const { filePath, includeImages = true, includeStyles = true } = args;
|
|
1080
|
+
const escapedFilePath = escapeFilePathForJsx(filePath);
|
|
1081
|
+
|
|
1082
|
+
const script = [
|
|
1083
|
+
'if (app.documents.length === 0) {',
|
|
1084
|
+
' "No document open";',
|
|
1085
|
+
'} else {',
|
|
1086
|
+
' var doc = app.activeDocument;',
|
|
1087
|
+
' try {',
|
|
1088
|
+
` var xmlFile = File("${escapedFilePath}");`,
|
|
1089
|
+
' doc.exportFile(ExportFormat.XML_TYPE, xmlFile, false);',
|
|
1090
|
+
' "Document exported as XML successfully";',
|
|
1091
|
+
' } catch (error) {',
|
|
1092
|
+
' "Error exporting XML: " + error.message;',
|
|
1093
|
+
' }',
|
|
1094
|
+
'}'
|
|
1095
|
+
].join('\n');
|
|
1096
|
+
|
|
1097
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1098
|
+
return formatResponse(result, "Export Document XML");
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// =================== DOCUMENT CLOUD & COLLABORATION ===================
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* Save document to Adobe Creative Cloud
|
|
1105
|
+
*/
|
|
1106
|
+
static async saveDocumentToCloud(args) {
|
|
1107
|
+
const { cloudName, includeAssets = true } = args;
|
|
1108
|
+
const escapedCloudName = escapeJsxString(cloudName);
|
|
1109
|
+
|
|
1110
|
+
const script = [
|
|
1111
|
+
'if (app.documents.length === 0) {',
|
|
1112
|
+
' "No document open";',
|
|
1113
|
+
'} else {',
|
|
1114
|
+
' var doc = app.activeDocument;',
|
|
1115
|
+
' try {',
|
|
1116
|
+
' if (doc.isCloudDocument) {',
|
|
1117
|
+
' doc.save();',
|
|
1118
|
+
' "Cloud document saved successfully";',
|
|
1119
|
+
' } else {',
|
|
1120
|
+
` doc.saveACopyCloud("${escapedCloudName}");`,
|
|
1121
|
+
' "Document saved to cloud as: ' + escapedCloudName + '";',
|
|
1122
|
+
' }',
|
|
1123
|
+
' } catch (error) {',
|
|
1124
|
+
' "Error saving to cloud: " + error.message;',
|
|
1125
|
+
' }',
|
|
1126
|
+
'}'
|
|
1127
|
+
].join('\n');
|
|
1128
|
+
|
|
1129
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1130
|
+
return formatResponse(result, "Save Document to Cloud");
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Open a document from Adobe Creative Cloud
|
|
1135
|
+
*/
|
|
1136
|
+
static async openCloudDocument(args) {
|
|
1137
|
+
const { cloudDocumentId } = args;
|
|
1138
|
+
const escapedCloudDocumentId = escapeJsxString(cloudDocumentId);
|
|
1139
|
+
|
|
1140
|
+
const script = [
|
|
1141
|
+
'try {',
|
|
1142
|
+
` app.openCloudDocument("${escapedCloudDocumentId}");`,
|
|
1143
|
+
' "Cloud document opened successfully";',
|
|
1144
|
+
'} catch (error) {',
|
|
1145
|
+
' "Error opening cloud document: " + error.message;',
|
|
1146
|
+
'}'
|
|
1147
|
+
].join('\n');
|
|
1148
|
+
|
|
1149
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1150
|
+
return formatResponse(result, "Open Cloud Document");
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// =================== DOCUMENT GRID & LAYOUT ===================
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Get comprehensive grid settings for the document
|
|
1157
|
+
*/
|
|
1158
|
+
static async getDocumentGridSettings() {
|
|
1159
|
+
const script = [
|
|
1160
|
+
'if (app.documents.length === 0) {',
|
|
1161
|
+
' "No document open";',
|
|
1162
|
+
'} else {',
|
|
1163
|
+
' var doc = app.activeDocument;',
|
|
1164
|
+
' var result = "Document Grid Settings:\\n\\n";',
|
|
1165
|
+
'',
|
|
1166
|
+
' result += "=== GRID PREFERENCES ===\\n";',
|
|
1167
|
+
' try {',
|
|
1168
|
+
' result += "Document Grid Color: " + doc.gridPreferences.documentGridColor + "\\n";',
|
|
1169
|
+
' } catch (e) {',
|
|
1170
|
+
' result += "Document Grid Color: Not available\\n";',
|
|
1171
|
+
' }',
|
|
1172
|
+
' try {',
|
|
1173
|
+
' result += "Document Grid Increment: " + doc.gridPreferences.documentGridIncrement + "\\n";',
|
|
1174
|
+
' } catch (e) {',
|
|
1175
|
+
' result += "Document Grid Increment: Not available\\n";',
|
|
1176
|
+
' }',
|
|
1177
|
+
' try {',
|
|
1178
|
+
' result += "Document Grid Subdivision: " + doc.gridPreferences.documentGridSubdivision + "\\n";',
|
|
1179
|
+
' } catch (e) {',
|
|
1180
|
+
' result += "Document Grid Subdivision: Not available\\n";',
|
|
1181
|
+
' }',
|
|
1182
|
+
' try {',
|
|
1183
|
+
' result += "Grid View Threshold: " + doc.gridPreferences.gridViewThreshold + "\\n";',
|
|
1184
|
+
' } catch (e) {',
|
|
1185
|
+
' result += "Grid View Threshold: Not available\\n";',
|
|
1186
|
+
' }',
|
|
1187
|
+
'',
|
|
1188
|
+
' result += "\\n=== BASELINE GRID ===\\n";',
|
|
1189
|
+
' try {',
|
|
1190
|
+
' result += "Baseline Grid Color: " + doc.gridPreferences.baselineGridColor + "\\n";',
|
|
1191
|
+
' } catch (e) {',
|
|
1192
|
+
' result += "Baseline Grid Color: Not available\\n";',
|
|
1193
|
+
' }',
|
|
1194
|
+
' try {',
|
|
1195
|
+
' result += "Baseline Grid Increment: " + doc.gridPreferences.baselineGridIncrement + "\\n";',
|
|
1196
|
+
' } catch (e) {',
|
|
1197
|
+
' result += "Baseline Grid Increment: Not available\\n";',
|
|
1198
|
+
' }',
|
|
1199
|
+
' try {',
|
|
1200
|
+
' result += "Baseline Grid Offset: " + doc.gridPreferences.baselineGridOffset + "\\n";',
|
|
1201
|
+
' } catch (e) {',
|
|
1202
|
+
' result += "Baseline Grid Offset: Not available\\n";',
|
|
1203
|
+
' }',
|
|
1204
|
+
' try {',
|
|
1205
|
+
' result += "Baseline Grid View Threshold: " + doc.gridPreferences.baselineGridViewThreshold + "\\n";',
|
|
1206
|
+
' } catch (e) {',
|
|
1207
|
+
' result += "Baseline Grid View Threshold: Not available\\n";',
|
|
1208
|
+
' }',
|
|
1209
|
+
'',
|
|
1210
|
+
' result += "\\n=== GRID ALIGNMENT ===\\n";',
|
|
1211
|
+
' try {',
|
|
1212
|
+
' result += "Grid Alignment: " + doc.gridPreferences.gridAlignment + "\\n";',
|
|
1213
|
+
' } catch (e) {',
|
|
1214
|
+
' result += "Grid Alignment: Not available\\n";',
|
|
1215
|
+
' }',
|
|
1216
|
+
'',
|
|
1217
|
+
' result;',
|
|
1218
|
+
'}'
|
|
1219
|
+
].join('\n');
|
|
1220
|
+
|
|
1221
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1222
|
+
return formatResponse(result, "Get Document Grid Settings");
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Set comprehensive grid settings for the document
|
|
1227
|
+
*/
|
|
1228
|
+
static async setDocumentGridSettings(args) {
|
|
1229
|
+
const {
|
|
1230
|
+
documentGridColor = null,
|
|
1231
|
+
documentGridIncrement = null,
|
|
1232
|
+
documentGridSubdivision = null,
|
|
1233
|
+
baselineGridColor = null,
|
|
1234
|
+
baselineGridIncrement = null,
|
|
1235
|
+
baselineGridOffset = null,
|
|
1236
|
+
baselineGridViewThreshold = null,
|
|
1237
|
+
gridViewThreshold = null,
|
|
1238
|
+
gridAlignment = null
|
|
1239
|
+
} = args;
|
|
1240
|
+
|
|
1241
|
+
const lines = [];
|
|
1242
|
+
const safeSet = (name, statement) => (
|
|
1243
|
+
`try { ${statement} updatedCount++; } catch (e) { skipped.push("${name}: " + e.message); }`
|
|
1244
|
+
);
|
|
1245
|
+
if (documentGridColor !== null) lines.push(safeSet('documentGridColor', `doc.gridPreferences.documentGridColor = "${escapeJsxString(documentGridColor)}";`));
|
|
1246
|
+
if (documentGridIncrement !== null) lines.push(safeSet('documentGridIncrement', `doc.gridPreferences.documentGridIncrement = UnitValue("${documentGridIncrement}mm");`));
|
|
1247
|
+
if (documentGridSubdivision !== null) lines.push(safeSet('documentGridSubdivision', `doc.gridPreferences.documentGridSubdivision = ${documentGridSubdivision};`));
|
|
1248
|
+
if (gridViewThreshold !== null) lines.push(safeSet('gridViewThreshold', `doc.gridPreferences.gridViewThreshold = ${gridViewThreshold};`));
|
|
1249
|
+
|
|
1250
|
+
if (baselineGridColor !== null) lines.push(safeSet('baselineGridColor', `doc.gridPreferences.baselineGridColor = "${escapeJsxString(baselineGridColor)}";`));
|
|
1251
|
+
if (baselineGridIncrement !== null) lines.push(safeSet('baselineGridIncrement', `doc.gridPreferences.baselineGridIncrement = UnitValue("${baselineGridIncrement}mm");`));
|
|
1252
|
+
if (baselineGridOffset !== null) lines.push(safeSet('baselineGridOffset', `doc.gridPreferences.baselineGridOffset = UnitValue("${baselineGridOffset}mm");`));
|
|
1253
|
+
if (baselineGridViewThreshold !== null) lines.push(safeSet('baselineGridViewThreshold', `doc.gridPreferences.baselineGridViewThreshold = ${baselineGridViewThreshold};`));
|
|
1254
|
+
|
|
1255
|
+
if (gridAlignment !== null) lines.push(safeSet('gridAlignment', `doc.gridPreferences.gridAlignment = "${escapeJsxString(gridAlignment)}";`));
|
|
1256
|
+
|
|
1257
|
+
const script = [
|
|
1258
|
+
'if (app.documents.length === 0) {',
|
|
1259
|
+
' "No document open";',
|
|
1260
|
+
'} else {',
|
|
1261
|
+
' var doc = app.activeDocument;',
|
|
1262
|
+
' var updatedCount = 0;',
|
|
1263
|
+
' var skipped = [];',
|
|
1264
|
+
' try {',
|
|
1265
|
+
...(lines.length ? lines : [' // No grid settings provided']),
|
|
1266
|
+
' "Document grid settings updated successfully. Updated: " + updatedCount + ", skipped: " + skipped.length;',
|
|
1267
|
+
' } catch (error) {',
|
|
1268
|
+
' "Error updating grid settings: " + error.message;',
|
|
1269
|
+
' }',
|
|
1270
|
+
'}'
|
|
1271
|
+
].join('\n');
|
|
1272
|
+
|
|
1273
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1274
|
+
return formatResponse(result, "Set Document Grid Settings");
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Get layout preferences and settings
|
|
1279
|
+
*/
|
|
1280
|
+
static async getDocumentLayoutPreferences() {
|
|
1281
|
+
const script = [
|
|
1282
|
+
'if (app.documents.length === 0) {',
|
|
1283
|
+
' "No document open";',
|
|
1284
|
+
'} else {',
|
|
1285
|
+
' var doc = app.activeDocument;',
|
|
1286
|
+
' var result = "Document Layout Preferences:\\n\\n";',
|
|
1287
|
+
'',
|
|
1288
|
+
' result += "=== ADJUST LAYOUT ===\\n";',
|
|
1289
|
+
' try {',
|
|
1290
|
+
' result += "Adjust Layout Enabled: " + doc.adjustLayoutPreferences.adjustLayout + "\\n";',
|
|
1291
|
+
' } catch (e) {',
|
|
1292
|
+
' result += "Adjust Layout Enabled: Not available\\n";',
|
|
1293
|
+
' }',
|
|
1294
|
+
' try {',
|
|
1295
|
+
' result += "Adjust Layout Margins: " + doc.adjustLayoutPreferences.adjustLayoutMargins + "\\n";',
|
|
1296
|
+
' } catch (e) {',
|
|
1297
|
+
' result += "Adjust Layout Margins: Not available\\n";',
|
|
1298
|
+
' }',
|
|
1299
|
+
' try {',
|
|
1300
|
+
' result += "Adjust Layout Page Breaks: " + doc.adjustLayoutPreferences.adjustLayoutPageBreaks + "\\n";',
|
|
1301
|
+
' } catch (e) {',
|
|
1302
|
+
' result += "Adjust Layout Page Breaks: Not available\\n";',
|
|
1303
|
+
' }',
|
|
1304
|
+
' try {',
|
|
1305
|
+
' result += "Adjust Layout Rules: " + doc.adjustLayoutPreferences.adjustLayoutRules + "\\n";',
|
|
1306
|
+
' } catch (e) {',
|
|
1307
|
+
' result += "Adjust Layout Rules: Not available\\n";',
|
|
1308
|
+
' }',
|
|
1309
|
+
'',
|
|
1310
|
+
' result += "\\n=== ALIGN & DISTRIBUTE ===\\n";',
|
|
1311
|
+
' try {',
|
|
1312
|
+
' result += "Align Distribute Bounds: " + doc.alignDistributePreferences.alignDistributeBounds + "\\n";',
|
|
1313
|
+
' } catch (e) {',
|
|
1314
|
+
' result += "Align Distribute Bounds: Not available\\n";',
|
|
1315
|
+
' }',
|
|
1316
|
+
' try {',
|
|
1317
|
+
' result += "Align Distribute Spacing: " + doc.alignDistributePreferences.alignDistributeSpacing + "\\n";',
|
|
1318
|
+
' } catch (e) {',
|
|
1319
|
+
' result += "Align Distribute Spacing: Not available\\n";',
|
|
1320
|
+
' }',
|
|
1321
|
+
'',
|
|
1322
|
+
' result += "\\n=== SMART GUIDES ===\\n";',
|
|
1323
|
+
' try {',
|
|
1324
|
+
' result += "Smart Guide Preferences: " + doc.smartGuidePreferences.smartGuidePreferences + "\\n";',
|
|
1325
|
+
' } catch (e) {',
|
|
1326
|
+
' result += "Smart Guide Preferences: Not available\\n";',
|
|
1327
|
+
' }',
|
|
1328
|
+
'',
|
|
1329
|
+
' result;',
|
|
1330
|
+
'}'
|
|
1331
|
+
].join('\n');
|
|
1332
|
+
|
|
1333
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1334
|
+
return formatResponse(result, "Get Document Layout Preferences");
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Set layout preferences for the document
|
|
1339
|
+
*/
|
|
1340
|
+
static async setDocumentLayoutPreferences(args) {
|
|
1341
|
+
const {
|
|
1342
|
+
adjustLayout = null,
|
|
1343
|
+
adjustLayoutMargins = null,
|
|
1344
|
+
adjustLayoutPageBreaks = null,
|
|
1345
|
+
adjustLayoutRules = null,
|
|
1346
|
+
alignDistributeBounds = null,
|
|
1347
|
+
alignDistributeSpacing = null,
|
|
1348
|
+
smartGuidePreferences = null
|
|
1349
|
+
} = args;
|
|
1350
|
+
|
|
1351
|
+
const lines = [];
|
|
1352
|
+
const safeSet = (name, statement) => (
|
|
1353
|
+
`try { ${statement} updatedCount++; } catch (e) { skipped.push("${name}: " + e.message); }`
|
|
1354
|
+
);
|
|
1355
|
+
if (adjustLayout !== null) lines.push(safeSet('adjustLayout', `doc.adjustLayoutPreferences.adjustLayout = ${adjustLayout};`));
|
|
1356
|
+
if (adjustLayoutMargins !== null) lines.push(safeSet('adjustLayoutMargins', `doc.adjustLayoutPreferences.adjustLayoutMargins = ${adjustLayoutMargins};`));
|
|
1357
|
+
if (adjustLayoutPageBreaks !== null) lines.push(safeSet('adjustLayoutPageBreaks', `doc.adjustLayoutPreferences.adjustLayoutPageBreaks = ${adjustLayoutPageBreaks};`));
|
|
1358
|
+
if (adjustLayoutRules) lines.push(safeSet('adjustLayoutRules', `doc.adjustLayoutPreferences.adjustLayoutRules = "${escapeJsxString(adjustLayoutRules)}";`));
|
|
1359
|
+
|
|
1360
|
+
if (alignDistributeBounds) lines.push(safeSet('alignDistributeBounds', `doc.alignDistributePreferences.alignDistributeBounds = "${escapeJsxString(alignDistributeBounds)}";`));
|
|
1361
|
+
if (alignDistributeSpacing) lines.push(safeSet('alignDistributeSpacing', `doc.alignDistributePreferences.alignDistributeSpacing = "${escapeJsxString(alignDistributeSpacing)}";`));
|
|
1362
|
+
|
|
1363
|
+
if (smartGuidePreferences !== null) lines.push(safeSet('smartGuidePreferences', `doc.smartGuidePreferences.smartGuidePreferences = ${smartGuidePreferences};`));
|
|
1364
|
+
|
|
1365
|
+
const script = [
|
|
1366
|
+
'if (app.documents.length === 0) {',
|
|
1367
|
+
' "No document open";',
|
|
1368
|
+
'} else {',
|
|
1369
|
+
' var doc = app.activeDocument;',
|
|
1370
|
+
' var updatedCount = 0;',
|
|
1371
|
+
' var skipped = [];',
|
|
1372
|
+
' try {',
|
|
1373
|
+
...(lines.length ? lines : [' // No layout preference changes provided']),
|
|
1374
|
+
' "Document layout preferences updated successfully. Updated: " + updatedCount + ", skipped: " + skipped.length;',
|
|
1375
|
+
' } catch (error) {',
|
|
1376
|
+
' "Error updating layout preferences: " + error.message;',
|
|
1377
|
+
' }',
|
|
1378
|
+
'}'
|
|
1379
|
+
].join('\n');
|
|
1380
|
+
|
|
1381
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1382
|
+
return formatResponse(result, "Set Document Layout Preferences");
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// =================== DOCUMENT VALIDATION & CLEANUP ===================
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Validate document structure and content
|
|
1389
|
+
*/
|
|
1390
|
+
static async validateDocument(args) {
|
|
1391
|
+
const { checkLinks = true, checkFonts = true, checkImages = true, checkStyles = false } = args;
|
|
1392
|
+
|
|
1393
|
+
const script = [
|
|
1394
|
+
'if (app.documents.length === 0) {',
|
|
1395
|
+
' "No document open";',
|
|
1396
|
+
'} else {',
|
|
1397
|
+
' var doc = app.activeDocument;',
|
|
1398
|
+
' var validation = {',
|
|
1399
|
+
' isValid: true,',
|
|
1400
|
+
' issues: []',
|
|
1401
|
+
' };',
|
|
1402
|
+
'',
|
|
1403
|
+
' try {',
|
|
1404
|
+
' if (' + checkLinks + ') {',
|
|
1405
|
+
' for (var i = 0; i < doc.links.length; i++) {',
|
|
1406
|
+
' if (!doc.links[i].isValid) {',
|
|
1407
|
+
' validation.issues.push("Broken link: " + doc.links[i].name);',
|
|
1408
|
+
' validation.isValid = false;',
|
|
1409
|
+
' }',
|
|
1410
|
+
' }',
|
|
1411
|
+
' }',
|
|
1412
|
+
'',
|
|
1413
|
+
' if (' + checkFonts + ') {',
|
|
1414
|
+
' for (var i = 0; i < doc.fonts.length; i++) {',
|
|
1415
|
+
' if (!doc.fonts[i].isValid) {',
|
|
1416
|
+
' validation.issues.push("Missing font: " + doc.fonts[i].name);',
|
|
1417
|
+
' validation.isValid = false;',
|
|
1418
|
+
' }',
|
|
1419
|
+
' }',
|
|
1420
|
+
' }',
|
|
1421
|
+
'',
|
|
1422
|
+
' JSON.stringify(validation);',
|
|
1423
|
+
' } catch (error) {',
|
|
1424
|
+
' "Error validating document: " + error.message;',
|
|
1425
|
+
' }',
|
|
1426
|
+
'}'
|
|
1427
|
+
].join('\n');
|
|
1428
|
+
|
|
1429
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1430
|
+
return formatResponse(result, "Validate Document");
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* Clean up document (remove unused elements)
|
|
1435
|
+
*/
|
|
1436
|
+
static async cleanupDocument(args) {
|
|
1437
|
+
const { removeUnusedStyles = false, removeUnusedColors = false, removeUnusedLayers = false, removeHiddenElements = false } = args;
|
|
1438
|
+
|
|
1439
|
+
const script = [
|
|
1440
|
+
'if (app.documents.length === 0) {',
|
|
1441
|
+
' "No document open";',
|
|
1442
|
+
'} else {',
|
|
1443
|
+
' var doc = app.activeDocument;',
|
|
1444
|
+
' var cleanup = {',
|
|
1445
|
+
' actions: [],',
|
|
1446
|
+
' removedItems: 0',
|
|
1447
|
+
' };',
|
|
1448
|
+
'',
|
|
1449
|
+
' try {',
|
|
1450
|
+
' if (' + removeUnusedStyles + ') {',
|
|
1451
|
+
' var unusedStyles = doc.unusedSwatches;',
|
|
1452
|
+
' cleanup.removedItems += unusedStyles.length;',
|
|
1453
|
+
' cleanup.actions.push("Found " + unusedStyles.length + " unused styles");',
|
|
1454
|
+
' }',
|
|
1455
|
+
'',
|
|
1456
|
+
' if (' + removeUnusedColors + ') {',
|
|
1457
|
+
' var unusedColors = doc.unusedSwatches;',
|
|
1458
|
+
' cleanup.removedItems += unusedColors.length;',
|
|
1459
|
+
' cleanup.actions.push("Found " + unusedColors.length + " unused colors");',
|
|
1460
|
+
' }',
|
|
1461
|
+
'',
|
|
1462
|
+
' JSON.stringify(cleanup);',
|
|
1463
|
+
' } catch (error) {',
|
|
1464
|
+
' "Error cleaning up document: " + error.message;',
|
|
1465
|
+
' }',
|
|
1466
|
+
'}'
|
|
1467
|
+
].join('\n');
|
|
1468
|
+
|
|
1469
|
+
const result = await ScriptExecutor.executeInDesignScript(script);
|
|
1470
|
+
return formatResponse(result, "Cleanup Document");
|
|
1471
|
+
}
|
|
1472
|
+
}
|