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

UXP InDesign Plugin. Is it possible to place *.indt "constant template file" inside the plugin?

Participant ,
Sep 17, 2023 Sep 17, 2023

Hello everybody!
I have a file (an unfinished *.indt template) and I want to place it inside the plugin file structure. I want to develop a command that will open this file, make some corrections to a set of text variables, and then the user will save it as a new *.indd .
Is it possible to do this? I still don't understand what path it will have, being located in the plugin, and how to get to it...
It is not desirable that this file be edited by the end user, so I would like to hide this file inside.

const entry = await localFileSystem.getEntry("../ugj2023.indt");

I tried to play with something like this, but there is no reaction. 

TOPICS
UXP Scripting
579
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

correct answers 1 Correct answer

Participant , Sep 18, 2023 Sep 18, 2023

The solution has just been found. If you need to open the InDesign template file hidden in the plugin assembly, this is solved with a couple of lines:

const { app } = require("indesign");
const fs = require("uxp").storage.localFileSystem;

async function createNewDocFromTemplate() {
    // Plugin Folder
    const folder = await fs.getPluginFolder(); 

    // Entry (file) "ugj2023.indt" in the folder "ugj" 
    const entry = await folder.getEntry("ugj/ugj2023.indt"); 
    app.open(entry); /// ugj2
...
Translate
LEGEND ,
Sep 17, 2023 Sep 17, 2023

Even if you could store indt file in a binary form - how do you plan on updating your script - when it is running? Will JS allow you to overwrite itself during execution? 

 

I'm not JS expert so just speculating. 

 

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
Participant ,
Sep 17, 2023 Sep 17, 2023

The plugin (working version) will not be changed in any way programmatically during operation. The idea is that there is no need to place the template file on some computer in a previously unknown location, keep the path to it, and check each time whether it still exists at this path and whether its version corresponds to the version of the plugin. It's easier to store it inside the plugin's file structure.
If a *.indt file is opened, InDesign offers to save it already as a working *.indd file. And before that, I can set some clarifying parameters, for example through a dialog. The *.indt file is not planned to be "returned" to the plugin after making changes.

The problem is in the vaguely formulated description of the "fs", and "uxp" modules. There are apparently few examples.

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
Participant ,
Sep 18, 2023 Sep 18, 2023
LATEST

The solution has just been found. If you need to open the InDesign template file hidden in the plugin assembly, this is solved with a couple of lines:

const { app } = require("indesign");
const fs = require("uxp").storage.localFileSystem;

async function createNewDocFromTemplate() {
    // Plugin Folder
    const folder = await fs.getPluginFolder(); 

    // Entry (file) "ugj2023.indt" in the folder "ugj" 
    const entry = await folder.getEntry("ugj/ugj2023.indt"); 
    app.open(entry); /// ugj2023.indt is now active document...
}

module.exports = { createNewDocFromTemplate };

It is very difficult to use the provided information about UXP, unfortunately...

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