Skip to main content
vnh68
Inspiring
Sep 17, 2023 8:15 PM UTC
Answered

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

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. 

This topic is closed to new replies. Start a new post to keep the conversation going.
vnh68
vnh68Correct answer
Inspiring
Sep 18, 2023 1:07 PM UTC

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...

3 replies

Robert at ID-Tasker
Legend
Sep 18, 2023 12:53 AM UTC

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
vnh68
vnh68Author
Inspiring
Sep 18, 2023 5:39 AM UTC

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
vnh68
vnh68AuthorCorrect answer
Inspiring
Sep 18, 2023 1:07 PM UTC

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