@ajsmonty/adobe-mcp 1.1.2 → 1.5.0
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/CHANGELOG.md +19 -0
- package/README.md +361 -119
- package/SECURITY.md +24 -1
- package/adapters/ae_more.mjs +208 -0
- package/adapters/an.mjs +96 -0
- package/adapters/assets.mjs +194 -0
- package/adapters/blender.mjs +230 -0
- package/adapters/id.mjs +250 -0
- package/adapters/ppro.mjs +4 -3
- package/adapters/ppro_more.mjs +393 -0
- package/adapters/ps_ai_more.mjs +277 -0
- package/adapters/substance.mjs +193 -0
- package/adapters/texlib.mjs +193 -0
- package/bridges/blender/adobe_mcp_bridge.py +132 -0
- package/cep/mcp-bridge/CSXS/manifest.xml +36 -2
- package/cep/mcp-bridge/main.js +48 -20
- package/cli/doctor.mjs +234 -0
- package/cli/index.mjs +67 -0
- package/cli/install.mjs +149 -0
- package/core/barrows.mjs +16 -0
- package/core/blender_pbr.py +148 -0
- package/core/bridge.mjs +166 -77
- package/core/harness.jsx +11 -6
- package/core/harness.py +34 -0
- package/core/helpers.mjs +196 -0
- package/core/platform.mjs +209 -0
- package/core/pybridge.mjs +256 -0
- package/core/telemetry.mjs +80 -0
- package/core/texlib.mjs +279 -0
- package/core/win/run_com.js +33 -0
- package/core/workspace.mjs +1 -1
- package/knowledge/knowledge.mjs +8 -5
- package/knowledge/lessons.jsonl +19 -0
- package/package.json +56 -3
- package/scripts/ae/Cinematic_3D_Composite.jsx +173 -0
- package/scripts/blender/Creature_Walk_Cinematic.py +569 -0
- package/scripts/substance/Creature_Skin_LookDev.py +148 -0
- package/server.mjs +92 -27
- package/workflow/setup.mjs +106 -0
- package/workflow/vfx.mjs +136 -0
- package/workflow/workflow.mjs +66 -21
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// Blender adapter — Python (bpy) via the live add-on or a headless background process.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { runBlender, blenderSaveSnippet } from "../core/pybridge.mjs";
|
|
7
|
+
|
|
8
|
+
const MODE = z
|
|
9
|
+
.enum(["auto", "live", "background"])
|
|
10
|
+
.optional()
|
|
11
|
+
.describe(
|
|
12
|
+
"live = the running Blender (needs the adobe-mcp add-on), background = headless process, " +
|
|
13
|
+
"auto (default) = live if the add-on answers and no blend_file is given, else background."
|
|
14
|
+
);
|
|
15
|
+
const BLEND = z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Absolute .blend path to open (background mode). Without it background starts from factory settings.");
|
|
19
|
+
|
|
20
|
+
const STATE_PY = `
|
|
21
|
+
import bpy
|
|
22
|
+
s = bpy.context.scene
|
|
23
|
+
r = s.render
|
|
24
|
+
objs = []
|
|
25
|
+
for o in s.objects:
|
|
26
|
+
rec = {"name": o.name, "type": o.type, "location": [round(v, 4) for v in o.location],
|
|
27
|
+
"rotation_euler": [round(v, 4) for v in o.rotation_euler], "scale": [round(v, 4) for v in o.scale],
|
|
28
|
+
"parent": o.parent.name if o.parent else None, "hide_render": o.hide_render,
|
|
29
|
+
"animated": bool(o.animation_data and o.animation_data.action)}
|
|
30
|
+
if o.type == "CAMERA":
|
|
31
|
+
rec["lens_mm"] = o.data.lens; rec["sensor_mm"] = o.data.sensor_width
|
|
32
|
+
rec["dof"] = {"use": o.data.dof.use_dof, "fstop": o.data.dof.aperture_fstop,
|
|
33
|
+
"focus_object": o.data.dof.focus_object.name if o.data.dof.focus_object else None}
|
|
34
|
+
elif o.type == "ARMATURE":
|
|
35
|
+
rec["bones"] = [b.name for b in o.data.bones][:200]
|
|
36
|
+
elif o.type == "MESH":
|
|
37
|
+
rec["verts"] = len(o.data.vertices); rec["materials"] = [m.name for m in o.data.materials if m]
|
|
38
|
+
objs.append(rec)
|
|
39
|
+
vl = bpy.context.view_layer
|
|
40
|
+
passes = [p for p in ("use_pass_z", "use_pass_mist", "use_pass_normal", "use_pass_ambient_occlusion",
|
|
41
|
+
"use_pass_cryptomatte_object") if getattr(vl, p, False)]
|
|
42
|
+
if getattr(getattr(vl, "cycles", None), "use_pass_shadow_catcher", False):
|
|
43
|
+
passes.append("use_pass_shadow_catcher")
|
|
44
|
+
result = {
|
|
45
|
+
"blender": bpy.app.version_string, "file": bpy.data.filepath or None, "scene": s.name,
|
|
46
|
+
"frame_range": [s.frame_start, s.frame_end], "frame_current": s.frame_current,
|
|
47
|
+
"fps": round(r.fps / r.fps_base, 3), "resolution": [r.resolution_x, r.resolution_y, r.resolution_percentage],
|
|
48
|
+
"engine": r.engine, "motion_blur": r.use_motion_blur, "shutter": r.motion_blur_shutter,
|
|
49
|
+
"camera": s.camera.name if s.camera else None, "output": r.filepath,
|
|
50
|
+
"file_format": r.image_settings.file_format, "passes": passes,
|
|
51
|
+
"unit_scale": s.unit_settings.scale_length, "objects": objs,
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export function register(server, { text, errText, registerAsset }) {
|
|
56
|
+
server.registerTool(
|
|
57
|
+
"blender_run_python",
|
|
58
|
+
{
|
|
59
|
+
title: "Run Python (bpy) in Blender",
|
|
60
|
+
description:
|
|
61
|
+
"Execute Python inside Blender with bpy available. Runs as a module body; set `result = <value>` " +
|
|
62
|
+
"to return JSON (print() output comes back as stdout). Check objects exist before touching them " +
|
|
63
|
+
"(bpy.data.objects.get(name)). Work in real-world meters/seconds; key animation with keyframe_insert. " +
|
|
64
|
+
"In background mode nothing persists unless you pass save_as (or call bpy.ops.wm.save_mainfile). " +
|
|
65
|
+
"GOTCHAS: Blender 5.x compositor lives in scene.compositing_node_group (scene.node_tree is gone); " +
|
|
66
|
+
"EEVEE engine id is 'BLENDER_EEVEE_NEXT' in 4.2–4.5 but 'BLENDER_EEVEE' in 5.x. More: knowledge_search app=blender.",
|
|
67
|
+
inputSchema: {
|
|
68
|
+
code: z.string().describe("Python source; assign `result` to return data."),
|
|
69
|
+
mode: MODE,
|
|
70
|
+
blend_file: BLEND,
|
|
71
|
+
save_as: z.string().optional().describe("Absolute .blend path to save to after the code runs."),
|
|
72
|
+
timeout_seconds: z.number().optional().describe("Max seconds (default 120)."),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
async ({ code, mode, blend_file, save_as, timeout_seconds }) => {
|
|
76
|
+
try {
|
|
77
|
+
const full = save_as
|
|
78
|
+
? `${code}\n${blenderSaveSnippet(save_as)}`
|
|
79
|
+
: code;
|
|
80
|
+
const r = await runBlender(full, { mode, blendFile: blend_file, timeoutMs: (timeout_seconds ?? 120) * 1000 });
|
|
81
|
+
if (save_as) registerAsset({ app: "blender", kind: "blend", path: save_as, meta: {} });
|
|
82
|
+
return text({ ok: true, ...r });
|
|
83
|
+
} catch (e) {
|
|
84
|
+
return errText(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
server.registerTool(
|
|
90
|
+
"blender_get_state",
|
|
91
|
+
{
|
|
92
|
+
title: "Inspect the Blender scene",
|
|
93
|
+
description:
|
|
94
|
+
"Scene summary: version, file, frame range, fps, resolution, engine, motion blur, active camera " +
|
|
95
|
+
"(lens/DoF), enabled render passes, and every object (type, transform, parent, animated, bones).",
|
|
96
|
+
inputSchema: { mode: MODE, blend_file: BLEND },
|
|
97
|
+
},
|
|
98
|
+
async ({ mode, blend_file }) => {
|
|
99
|
+
try {
|
|
100
|
+
const r = await runBlender(STATE_PY, { mode, blendFile: blend_file, timeoutMs: 60000 });
|
|
101
|
+
return text({ ...r.result, bridge_mode: r.mode });
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return errText(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
server.registerTool(
|
|
109
|
+
"blender_render_frame",
|
|
110
|
+
{
|
|
111
|
+
title: "Render a Blender frame to PNG",
|
|
112
|
+
description:
|
|
113
|
+
"Render one frame through the scene camera and return it inline so you can visually verify " +
|
|
114
|
+
"blocking, lighting and framing. Uses a reduced resolution and sample count for speed; scene " +
|
|
115
|
+
"render settings are restored afterwards.",
|
|
116
|
+
inputSchema: {
|
|
117
|
+
frame: z.number().int().optional().describe("Frame to render (default: current frame)."),
|
|
118
|
+
max_width: z.number().optional().describe("Preview width in px (default 960)."),
|
|
119
|
+
samples: z.number().int().optional().describe("Cycles/EEVEE samples for the preview (default 16)."),
|
|
120
|
+
mode: MODE,
|
|
121
|
+
blend_file: BLEND,
|
|
122
|
+
timeout_seconds: z.number().optional().describe("Max seconds (default 300)."),
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
async ({ frame, max_width, samples, mode, blend_file, timeout_seconds }) => {
|
|
126
|
+
const pngPath = path.join(os.tmpdir(), `adobe_mcp_blender_${Date.now()}.png`);
|
|
127
|
+
try {
|
|
128
|
+
const py = `
|
|
129
|
+
import bpy
|
|
130
|
+
s = bpy.context.scene
|
|
131
|
+
r = s.render
|
|
132
|
+
if s.camera is None:
|
|
133
|
+
raise RuntimeError("Scene has no active camera (set scene.camera)")
|
|
134
|
+
saved = dict(fp=r.filepath, fmt=r.image_settings.file_format, pct=r.resolution_percentage,
|
|
135
|
+
frame=s.frame_current, mode=r.image_settings.color_mode,
|
|
136
|
+
media=getattr(r.image_settings, "media_type", None), comp=r.use_compositing)
|
|
137
|
+
cy_samples = s.cycles.samples if r.engine == "CYCLES" else None
|
|
138
|
+
ee = getattr(s, "eevee", None)
|
|
139
|
+
ee_samples = ee.taa_render_samples if ee is not None and hasattr(ee, "taa_render_samples") else None
|
|
140
|
+
try:
|
|
141
|
+
frame = ${frame === undefined ? "s.frame_current" : Number(frame)}
|
|
142
|
+
s.frame_set(frame)
|
|
143
|
+
r.use_compositing = False # File Output nodes would write the preview into the pass sequences
|
|
144
|
+
r.resolution_percentage = max(1, min(100, int(100 * ${Number(max_width ?? 960)} / max(1, r.resolution_x))))
|
|
145
|
+
if cy_samples is not None: s.cycles.samples = ${Number(samples ?? 16)}
|
|
146
|
+
if ee_samples is not None: ee.taa_render_samples = ${Number(samples ?? 16)}
|
|
147
|
+
if saved["media"] is not None:
|
|
148
|
+
r.image_settings.media_type = "IMAGE" # Blender 5.x
|
|
149
|
+
r.image_settings.file_format = "PNG"
|
|
150
|
+
r.image_settings.color_mode = "RGBA"
|
|
151
|
+
r.filepath = ${JSON.stringify(pngPath)}
|
|
152
|
+
bpy.ops.render.render(write_still=True)
|
|
153
|
+
result = {"frame": frame, "engine": r.engine, "camera": s.camera.name,
|
|
154
|
+
"size": [r.resolution_x * r.resolution_percentage // 100, r.resolution_y * r.resolution_percentage // 100]}
|
|
155
|
+
finally:
|
|
156
|
+
r.filepath = saved["fp"]
|
|
157
|
+
r.use_compositing = saved["comp"]
|
|
158
|
+
if saved["media"] is not None:
|
|
159
|
+
r.image_settings.media_type = saved["media"]
|
|
160
|
+
r.image_settings.file_format = saved["fmt"]
|
|
161
|
+
r.image_settings.color_mode = saved["mode"]; r.resolution_percentage = saved["pct"]
|
|
162
|
+
if cy_samples is not None: s.cycles.samples = cy_samples
|
|
163
|
+
if ee_samples is not None: ee.taa_render_samples = ee_samples
|
|
164
|
+
s.frame_set(saved["frame"])
|
|
165
|
+
`;
|
|
166
|
+
const r = await runBlender(py, { mode, blendFile: blend_file, timeoutMs: (timeout_seconds ?? 300) * 1000 });
|
|
167
|
+
if (!fs.existsSync(pngPath)) throw new Error("Render finished but no PNG was written.");
|
|
168
|
+
const data = fs.readFileSync(pngPath).toString("base64");
|
|
169
|
+
fs.rmSync(pngPath, { force: true });
|
|
170
|
+
return {
|
|
171
|
+
content: [
|
|
172
|
+
{ type: "text", text: JSON.stringify({ ...r.result, bridge_mode: r.mode }) },
|
|
173
|
+
{ type: "image", data, mimeType: "image/png" },
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
} catch (e) {
|
|
177
|
+
fs.rmSync(pngPath, { force: true });
|
|
178
|
+
return errText(e);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
server.registerTool(
|
|
184
|
+
"blender_render_animation",
|
|
185
|
+
{
|
|
186
|
+
title: "Render a Blender animation to disk",
|
|
187
|
+
description:
|
|
188
|
+
"Render the scene's frame range (or an override) with the scene's own output settings — e.g. the " +
|
|
189
|
+
"multilayer EXR + pass sequences set up by scripts/blender/Creature_Walk_Cinematic.py — and register " +
|
|
190
|
+
"the output folder as a workflow asset for the After Effects handoff. Prefer mode 'background' with " +
|
|
191
|
+
"a saved blend_file for long renders so the Blender UI stays usable.",
|
|
192
|
+
inputSchema: {
|
|
193
|
+
output_dir: z.string().optional().describe("Directory for frames (default: scene output path)."),
|
|
194
|
+
frame_start: z.number().int().optional(),
|
|
195
|
+
frame_end: z.number().int().optional(),
|
|
196
|
+
mode: MODE,
|
|
197
|
+
blend_file: BLEND,
|
|
198
|
+
timeout_seconds: z.number().optional().describe("Max seconds (default 3600)."),
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
async ({ output_dir, frame_start, frame_end, mode, blend_file, timeout_seconds }) => {
|
|
202
|
+
try {
|
|
203
|
+
const py = `
|
|
204
|
+
import bpy, os
|
|
205
|
+
s = bpy.context.scene
|
|
206
|
+
r = s.render
|
|
207
|
+
if s.camera is None:
|
|
208
|
+
raise RuntimeError("Scene has no active camera")
|
|
209
|
+
out_dir = ${output_dir ? JSON.stringify(output_dir) : "None"}
|
|
210
|
+
if out_dir:
|
|
211
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
212
|
+
r.filepath = os.path.join(out_dir, (s.camera.name or "render") + "_")
|
|
213
|
+
${frame_start !== undefined ? `s.frame_start = ${Number(frame_start)}` : ""}
|
|
214
|
+
${frame_end !== undefined ? `s.frame_end = ${Number(frame_end)}` : ""}
|
|
215
|
+
bpy.ops.render.render(animation=True)
|
|
216
|
+
folder = os.path.dirname(bpy.path.abspath(r.filepath))
|
|
217
|
+
files = sorted(f for f in os.listdir(folder)) if os.path.isdir(folder) else []
|
|
218
|
+
result = {"output_dir": folder, "frames": [s.frame_start, s.frame_end], "file_format": r.image_settings.file_format,
|
|
219
|
+
"num_files": len(files), "sample": files[:5]}
|
|
220
|
+
`;
|
|
221
|
+
const r = await runBlender(py, { mode, blendFile: blend_file, timeoutMs: (timeout_seconds ?? 3600) * 1000 });
|
|
222
|
+
if (r.result?.output_dir)
|
|
223
|
+
registerAsset({ app: "blender", kind: "image-sequence", path: r.result.output_dir, meta: { frames: r.result.frames } });
|
|
224
|
+
return text({ ...r.result, bridge_mode: r.mode });
|
|
225
|
+
} catch (e) {
|
|
226
|
+
return errText(e);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
}
|
package/adapters/id.mjs
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// InDesign adapter (ExtendScript via AppleScript `do script` on macOS, COM DoScript on Windows).
|
|
2
|
+
// Ported from the Barrows line of adobe-mcp (contributions by Derrin Byrne).
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { runJSX, downscalePng } from "../core/bridge.mjs";
|
|
8
|
+
import { lit, esPath } from "../core/helpers.mjs";
|
|
9
|
+
|
|
10
|
+
const ID_LIB = `
|
|
11
|
+
var __uil = app.scriptPreferences.userInteractionLevel;
|
|
12
|
+
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
|
|
13
|
+
function restoreUI() { app.scriptPreferences.userInteractionLevel = __uil; }
|
|
14
|
+
function docFor(p) {
|
|
15
|
+
if (p) {
|
|
16
|
+
var f = new File(p);
|
|
17
|
+
for (var i = 0; i < app.documents.length; i++) if (app.documents[i].saved && app.documents[i].fullName.fsName === f.fsName) return app.documents[i];
|
|
18
|
+
if (!f.exists) throw new Error('File not found: ' + p);
|
|
19
|
+
return app.open(f);
|
|
20
|
+
}
|
|
21
|
+
if (!app.documents.length) throw new Error('No InDesign document is open.');
|
|
22
|
+
return app.activeDocument;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export function register(server, { text, errText, registerAsset }) {
|
|
27
|
+
server.registerTool(
|
|
28
|
+
"id_run_extendscript",
|
|
29
|
+
{
|
|
30
|
+
title: "Run ExtendScript in InDesign",
|
|
31
|
+
description:
|
|
32
|
+
"Execute ExtendScript (JSX) inside InDesign and return the result. Runs as a function body: end with " +
|
|
33
|
+
"`return <value>`. ES3 only. Key DOM: app.documents, activeDocument.pages, textFrames, allPageItems, " +
|
|
34
|
+
"paragraphStyles, links, exportFile(ExportFormat.PDF_TYPE, file, false, preset). Measurements use the " +
|
|
35
|
+
"document's units (viewPreferences). Set app.scriptPreferences.userInteractionLevel to NEVER_INTERACT to avoid dialogs.",
|
|
36
|
+
inputSchema: {
|
|
37
|
+
code: z.string().describe("ExtendScript function body."),
|
|
38
|
+
timeout_seconds: z.number().optional().describe("Max seconds (default 120)."),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
async ({ code, timeout_seconds }) => {
|
|
42
|
+
try {
|
|
43
|
+
const r = await runJSX("id", code, (timeout_seconds ?? 120) * 1000);
|
|
44
|
+
return text({ ok: true, result: r === undefined ? null : r });
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return errText(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
server.registerTool(
|
|
52
|
+
"id_get_state",
|
|
53
|
+
{
|
|
54
|
+
title: "Inspect open InDesign documents",
|
|
55
|
+
description:
|
|
56
|
+
"Lists open documents; for the active one returns pages, size, layers, named text frames with a preview " +
|
|
57
|
+
"of their text, paragraph styles, links (flagging missing/modified), missing fonts and data-merge fields.",
|
|
58
|
+
inputSchema: {},
|
|
59
|
+
},
|
|
60
|
+
async () => {
|
|
61
|
+
try {
|
|
62
|
+
const jsx = `
|
|
63
|
+
var out = { documents: [], active: null };
|
|
64
|
+
for (var i = 0; i < app.documents.length; i++) out.documents.push(app.documents[i].name);
|
|
65
|
+
if (app.documents.length) {
|
|
66
|
+
var d = app.activeDocument, a = { name: d.name, pages: d.pages.length, width: d.documentPreferences.pageWidth,
|
|
67
|
+
height: d.documentPreferences.pageHeight, units: String(d.viewPreferences.horizontalMeasurementUnits), layers: [], text_frames: [],
|
|
68
|
+
paragraph_styles: [], links: [], missing_fonts: [], merge_fields: [] };
|
|
69
|
+
for (var l = 0; l < d.layers.length; l++) a.layers.push(d.layers[l].name);
|
|
70
|
+
var tfs = d.textFrames;
|
|
71
|
+
for (var t = 0; t < tfs.length && t < 200; t++) { var tf = tfs[t];
|
|
72
|
+
var pg = null; try { pg = tf.parentPage ? tf.parentPage.name : null; } catch (e) {}
|
|
73
|
+
a.text_frames.push({ name: tf.name || tf.label || '', page: pg, text: String(tf.contents).substr(0, 80) }); }
|
|
74
|
+
for (var s = 0; s < d.paragraphStyles.length; s++) a.paragraph_styles.push(d.paragraphStyles[s].name);
|
|
75
|
+
for (var k = 0; k < d.links.length && k < 300; k++) { var L = d.links[k];
|
|
76
|
+
a.links.push({ name: L.name, status: L.status == LinkStatus.LINK_MISSING ? 'missing' : (L.status == LinkStatus.LINK_OUT_OF_DATE ? 'modified' : 'ok') }); }
|
|
77
|
+
for (var f = 0; f < d.fonts.length; f++) if (d.fonts[f].status != FontStatus.INSTALLED) a.missing_fonts.push(d.fonts[f].name);
|
|
78
|
+
try { var flds = d.dataMergeProperties.dataMergeFields; for (var m = 0; m < flds.length; m++) a.merge_fields.push(flds[m].fieldName); } catch (e) {}
|
|
79
|
+
out.active = a;
|
|
80
|
+
}
|
|
81
|
+
return out;`;
|
|
82
|
+
return text(await runJSX("id", jsx, 120000));
|
|
83
|
+
} catch (e) {
|
|
84
|
+
return errText(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
server.registerTool(
|
|
90
|
+
"id_fill_text",
|
|
91
|
+
{
|
|
92
|
+
title: "Fill named text frames in InDesign",
|
|
93
|
+
description:
|
|
94
|
+
"Set the text of frames by their name (Layers panel) or script label in the active document (or a given " +
|
|
95
|
+
"file). Keeps the frame's formatting. Unmatched names are reported with the available frame names.",
|
|
96
|
+
inputSchema: {
|
|
97
|
+
fields: z.record(z.string()).describe("{ frameName: newText }"),
|
|
98
|
+
document_path: z.string().optional().describe("Open this file instead of using the active document."),
|
|
99
|
+
save: z.boolean().optional().describe("Save the document afterwards (default false)."),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
async ({ fields, document_path, save }) => {
|
|
103
|
+
try {
|
|
104
|
+
const jsx = `${ID_LIB}
|
|
105
|
+
try {
|
|
106
|
+
var d = docFor(${lit(document_path ? esPath(document_path) : null)}), fields = ${lit(fields)}, set = [], missing = [], names = [];
|
|
107
|
+
var items = d.allPageItems;
|
|
108
|
+
for (var key in fields) {
|
|
109
|
+
var hit = 0;
|
|
110
|
+
for (var i = 0; i < items.length; i++) { var it = items[i];
|
|
111
|
+
if (it.constructor.name === 'TextFrame' && (it.name === key || it.label === key)) { it.contents = fields[key]; hit++; } }
|
|
112
|
+
if (hit) set.push(key); else missing.push(key);
|
|
113
|
+
}
|
|
114
|
+
if (missing.length) for (var j = 0; j < items.length; j++) if (items[j].constructor.name === 'TextFrame' && (items[j].name || items[j].label)) names.push(items[j].name || items[j].label);
|
|
115
|
+
var over = 0; for (var o = 0; o < d.textFrames.length; o++) if (d.textFrames[o].overflows) over++;
|
|
116
|
+
if (${lit(!!save)}) d.save();
|
|
117
|
+
return { document: d.name, set: set, not_found: missing, available_frame_names: names, frames_with_overset_text: over };
|
|
118
|
+
} finally { restoreUI(); }`;
|
|
119
|
+
return text(await runJSX("id", jsx, 120000));
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return errText(e);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
server.registerTool(
|
|
127
|
+
"id_export",
|
|
128
|
+
{
|
|
129
|
+
title: "Export an InDesign document",
|
|
130
|
+
description:
|
|
131
|
+
"Export the active document (or a given file) to PDF (with a named PDF preset such as '[High Quality " +
|
|
132
|
+
"Print]' or '[Press Quality]'), PNG or JPG. Page ranges like '1-3,5'. PNG/JPG export one file per page.",
|
|
133
|
+
inputSchema: {
|
|
134
|
+
output_path: z.string().describe("Absolute path; extension chooses the format (.pdf/.png/.jpg)."),
|
|
135
|
+
document_path: z.string().optional(),
|
|
136
|
+
pdf_preset: z.string().optional().describe("Default '[High Quality Print]'."),
|
|
137
|
+
pages: z.string().optional().describe("Page range, default all."),
|
|
138
|
+
resolution: z.number().optional().describe("PNG/JPG ppi (default 150)."),
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
async (a) => {
|
|
142
|
+
try {
|
|
143
|
+
const ext = path.extname(a.output_path).toLowerCase();
|
|
144
|
+
const jsx = `${ID_LIB}
|
|
145
|
+
try {
|
|
146
|
+
var d = docFor(${lit(a.document_path ? esPath(a.document_path) : null)}), f = new File(${lit(esPath(a.output_path))}), ext = ${lit(ext)};
|
|
147
|
+
new Folder(f.parent.fsName).create();
|
|
148
|
+
var range = ${lit(a.pages || null)};
|
|
149
|
+
if (ext === '.pdf') {
|
|
150
|
+
var pname = ${lit(a.pdf_preset || "[High Quality Print]")}, preset = app.pdfExportPresets.itemByName(pname);
|
|
151
|
+
if (!preset.isValid) { var names = []; for (var i = 0; i < app.pdfExportPresets.length; i++) names.push(app.pdfExportPresets[i].name);
|
|
152
|
+
throw new Error('PDF preset "' + pname + '" not found. Presets: ' + names.join(', ')); }
|
|
153
|
+
app.pdfExportPreferences.pageRange = range ? range : PageRange.ALL_PAGES;
|
|
154
|
+
d.exportFile(ExportFormat.PDF_TYPE, f, false, preset);
|
|
155
|
+
} else if (ext === '.png') {
|
|
156
|
+
var pp = app.pngExportPreferences; pp.exportResolution = ${lit(a.resolution ?? 150)};
|
|
157
|
+
pp.pngExportRange = range ? PNGExportRangeEnum.EXPORT_RANGE : PNGExportRangeEnum.EXPORT_ALL; if (range) pp.pageString = range;
|
|
158
|
+
d.exportFile(ExportFormat.PNG_FORMAT, f, false);
|
|
159
|
+
} else if (ext === '.jpg' || ext === '.jpeg') {
|
|
160
|
+
var jp = app.jpegExportPreferences; jp.exportResolution = ${lit(a.resolution ?? 150)}; jp.jpegQuality = JPEGOptionsQuality.MAXIMUM;
|
|
161
|
+
jp.jpegExportRange = range ? ExportRangeOrAllPages.EXPORT_RANGE : ExportRangeOrAllPages.EXPORT_ALL; if (range) jp.pageString = range;
|
|
162
|
+
d.exportFile(ExportFormat.JPG, f, false);
|
|
163
|
+
} else throw new Error('Use .pdf, .png or .jpg');
|
|
164
|
+
return { document: d.name, output: f.fsName };
|
|
165
|
+
} finally { restoreUI(); }`;
|
|
166
|
+
const r = await runJSX("id", jsx, 600000);
|
|
167
|
+
registerAsset?.({ app: "id", kind: ext.slice(1), path: a.output_path, meta: { doc: r.document } });
|
|
168
|
+
return text(r);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return errText(e);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
server.registerTool(
|
|
176
|
+
"id_save_preview",
|
|
177
|
+
{
|
|
178
|
+
title: "Preview an InDesign page",
|
|
179
|
+
description: "Render one page of the active document as an image and return it inline, so Claude can see the layout.",
|
|
180
|
+
inputSchema: {
|
|
181
|
+
page: z.string().optional().describe("Page name/number (default 1)."),
|
|
182
|
+
max_width: z.number().optional().describe("Max preview width in px (default 1024)."),
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
async ({ page, max_width }) => {
|
|
186
|
+
try {
|
|
187
|
+
const pngPath = path.join(os.tmpdir(), `adobe_mcp_id_preview_${Date.now()}.png`);
|
|
188
|
+
const jsx = `${ID_LIB}
|
|
189
|
+
try {
|
|
190
|
+
var d = docFor(null), pp = app.pngExportPreferences;
|
|
191
|
+
pp.exportResolution = 96; pp.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE; pp.pageString = ${lit(page || "1")};
|
|
192
|
+
d.exportFile(ExportFormat.PNG_FORMAT, new File(${lit(esPath(pngPath))}), false);
|
|
193
|
+
return { document: d.name, page: ${lit(page || "1")}, pages: d.pages.length };
|
|
194
|
+
} finally { restoreUI(); }`;
|
|
195
|
+
const meta = await runJSX("id", jsx, 180000);
|
|
196
|
+
if (!fs.existsSync(pngPath)) throw new Error("Preview image was not written.");
|
|
197
|
+
await downscalePng(pngPath, max_width ?? 1024);
|
|
198
|
+
const data = fs.readFileSync(pngPath).toString("base64");
|
|
199
|
+
fs.rmSync(pngPath, { force: true });
|
|
200
|
+
return { content: [{ type: "text", text: JSON.stringify(meta) }, { type: "image", data, mimeType: "image/png" }] };
|
|
201
|
+
} catch (e) {
|
|
202
|
+
return errText(e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
server.registerTool(
|
|
208
|
+
"id_data_merge",
|
|
209
|
+
{
|
|
210
|
+
title: "Run an InDesign data merge",
|
|
211
|
+
description:
|
|
212
|
+
"Run InDesign's built-in Data Merge on a template that already has merge fields placed (see id_get_state " +
|
|
213
|
+
"→ merge_fields) using a CSV/TXT data file, then export the merged result as a PDF. The template is not changed.",
|
|
214
|
+
inputSchema: {
|
|
215
|
+
template: z.string().describe("Absolute path to the .indd template."),
|
|
216
|
+
data_path: z.string().describe("CSV (comma) or TXT (tab) data file; headers must match the template's fields."),
|
|
217
|
+
output_pdf: z.string(),
|
|
218
|
+
pdf_preset: z.string().optional(),
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
async (a) => {
|
|
222
|
+
try {
|
|
223
|
+
const jsx = `${ID_LIB}
|
|
224
|
+
try {
|
|
225
|
+
var tpl = app.open(new File(${lit(esPath(a.template))})), merged;
|
|
226
|
+
try {
|
|
227
|
+
tpl.dataMergeProperties.selectDataSource(new File(${lit(esPath(a.data_path))}));
|
|
228
|
+
tpl.dataMergeProperties.mergeRecords();
|
|
229
|
+
merged = app.activeDocument;
|
|
230
|
+
var preset = app.pdfExportPresets.itemByName(${lit(a.pdf_preset || "[High Quality Print]")});
|
|
231
|
+
if (!preset.isValid) preset = app.pdfExportPresets[0];
|
|
232
|
+
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
|
|
233
|
+
var out = new File(${lit(esPath(a.output_pdf))}); new Folder(out.parent.fsName).create();
|
|
234
|
+
merged.exportFile(ExportFormat.PDF_TYPE, out, false, preset);
|
|
235
|
+
var pages = merged.pages.length;
|
|
236
|
+
} finally {
|
|
237
|
+
if (merged && merged !== tpl) merged.close(SaveOptions.NO);
|
|
238
|
+
tpl.close(SaveOptions.NO);
|
|
239
|
+
}
|
|
240
|
+
return { output: out.fsName, pages: pages };
|
|
241
|
+
} finally { restoreUI(); }`;
|
|
242
|
+
const r = await runJSX("id", jsx, 1200000);
|
|
243
|
+
registerAsset?.({ app: "id", kind: "pdf", path: a.output_pdf, meta: { merge: a.data_path } });
|
|
244
|
+
return text(r);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
return errText(e);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
}
|
package/adapters/ppro.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { runJSX, downscalePng, pproPanelAlive } from "../core/bridge.mjs";
|
|
7
|
+
import { findAdobeInstallDirs } from "../core/platform.mjs";
|
|
7
8
|
|
|
8
9
|
export function register(server, { text, errText, registerAsset }) {
|
|
9
10
|
server.registerTool(
|
|
@@ -204,9 +205,9 @@ return { time: t, width: fs2.videoFrameWidth, height: fs2.videoFrameHeight };`;
|
|
|
204
205
|
try {
|
|
205
206
|
let preset = preset_path;
|
|
206
207
|
if (!preset) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
// Newest Premiere install first (/Applications on macOS, Program Files\Adobe on Windows).
|
|
209
|
+
const roots = findAdobeInstallDirs(/^Adobe Premiere Pro/i).reverse();
|
|
210
|
+
outer: for (const base of roots) {
|
|
210
211
|
const stack = [base];
|
|
211
212
|
while (stack.length) {
|
|
212
213
|
const dir = stack.pop();
|