Skip to main content
vnh68
Inspiring
September 17, 2023
Answered

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

  • September 17, 2023
  • 1 reply
  • 593 views

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 has been closed for replies.
Correct answer vnh68

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

1 reply

Robert at ID-Tasker
Legend
September 18, 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. 

 

vnh68
vnh68Author
Inspiring
September 18, 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.

vnh68
vnh68AuthorCorrect answer
Inspiring
September 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); /// ugj2023.indt is now active document...
}

module.exports = { createNewDocFromTemplate };

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