Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

UXP Plugin – Cannot Access app.documents in InDesign

New Here ,
Mar 04, 2025 Mar 04, 2025

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(":rocket: Starting getParentPageObjects...");

        if (!app.documents || app.documents.length === 0) {
            throw new Error(":cross_mark: No InDesign document open!");
        }

        const document = app.activeDocument;
        console.log(":page_facing_up: Active document:", document.name);

        const masterSpreads = document.masterSpreads.everyItem().getElements();
        console.log(`:page_facing_up: Number of master spreads: ${masterSpreads.length}`);

        let masterPageNames = masterSpreads.map(spread => spread.name || "Unnamed");
        console.log(":scroll: Found master spreads:", masterPageNames);

    } catch (error) {
        console.error(":cross_mark: Error retrieving master spreads:", error);
    }
};

 


Error Message in the Console:
:bookmark_tabs: InDesign API loaded: ID { ... }
:open_file_folder: inDesignApp.documents: undefined
:cross_mark: Error retrieving master spreads: Error: :cross_mark: `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! 🙏😊






TOPICS
UXP Scripting
130
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 05, 2025 Mar 05, 2025
LATEST

Do you use a typescript preprocessor?

Otherwise try

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines