Skip to main content
tanjagandit
Participant
March 4, 2025
Question

UXP Plugin – Cannot Access app.documents in InDesign

  • March 4, 2025
  • 1 reply
  • 290 views

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:
InDesign API loaded: ID { ... }
inDesignApp.documents: undefined
❌ 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

  1. Why is app.documents undefined in UXP, even when a document is open?
  2. Is there a specific API or permission I might be missing?

I would really appreciate any help or guidance. Thank you in advance! 🙏😊






1 reply

Legend
March 5, 2025

Do you use a typescript preprocessor?

Otherwise try

const { app } = require("indesign");