UXP Plugin – Cannot Access app.documents in InDesign
Hello everyone,
I am developing a UXP plugin for InDesign (version 20.1.0) and I am trying to retrieve the master spreads of the currently open document. However, I am encountering an issue where app.documents is undefined in my UXP environment, even though a document is open.
My Code:
import { app } from "indesign";
const getParentPageObjects = async () => {
try {
console.log("🚀 Starting getParentPageObjects...");
if (!app.documents || app.documents.length === 0) {
throw new Error("❌ No InDesign document open!");
}
const document = app.activeDocument;
console.log("📄 Active document:", document.name);
const masterSpreads = document.masterSpreads.everyItem().getElements();
console.log(`📄 Number of master spreads: ${masterSpreads.length}`);
let masterPageNames = masterSpreads.map(spread => spread.name || "Unnamed");
console.log("📜 Found master spreads:", masterPageNames);
} catch (error) {
console.error("❌ Error retrieving master spreads:", error);
}
};
Error Message in the Console:
❌ Error retrieving master spreads: Error: ❌ `documents` is not defined. Missing permissions?
What I've Tried So Far:
Checked manifest.json:
"requiredPermissions": {
"localFileSystem": "request",
"uxp.app": "fullAccess",
"uxp.host": "fullAccess"
}
Tried executeAsModal
I attempted to use executeAsModal, but app.documents remains undefined
- Why is app.documents undefined in UXP, even when a document is open?
- Is there a specific API or permission I might be missing?
I would really appreciate any help or guidance. Thank you in advance! 🙏😊
