Skip to main content
Rosalyparis
New Participant
February 23, 2024
Answered

script to automatically RENAME indesign templates in with with their respective height x width

  • February 23, 2024
  • 2 replies
  • 352 views

I want create a script to automatically RENAME EXISTING indesign templates in the documets with their respective height x width dimensions.

Error 

JavaScript Erreur !

Numéro de l'erreur : 30474
Chaîne de l'erreur : 'name' est en lecture seule.

Moteur : main
Fichier : /Users/xxxx/Library/Preferences/Adobe InDesign/Version 19.0/fr_FR/Scripts/Scripts Panel/NOMMER LES GABARIT AUX FORMATS.jsx
Ligne : 24
Source : masterSpread.name = textFrame.contents;

--------------------------------------- MY script

// JavaScript pour renommer automatiquement les gabarits InDesign avec les dimensions

// Vérifier si un document est ouvert
if (app.documents.length > 0) {
// Récupérer le document actif
var doc = app.activeDocument;

// Parcourir tous les gabarits du document
for (var i = 0; i < doc.masterSpreads.length; i++) {
var masterSpread = doc.masterSpreads[i];

// Récupérer les dimensions du gabarit
var largeur = masterSpread.pages[0].bounds[3] - masterSpread.pages[0].bounds[1];
var hauteur = masterSpread.pages[0].bounds[2] - masterSpread.pages[0].bounds[0];

// Construire le nouveau nom du gabarit avec les dimensions
var nouveauNom = "Gabarit_" + Math.round(largeur) + "x" + Math.round(hauteur);

// Créer un champ de texte sur la première page du gabarit
var textFrame = masterSpread.pages[0].textFrames.add();
textFrame.contents = nouveauNom;

// Renommer le gabarit avec le contenu du champ de texte
masterSpread.name = textFrame.contents;

// Supprimer le champ de texte temporaire
textFrame.remove();
}

// Afficher un message une fois que le processus est terminé
alert("Le renommage des gabarits est terminé !");
} else {
// Afficher un message si aucun document n'est ouvert
alert("Aucun document ouvert. Veuillez ouvrir un document InDesign.");
}

Thanks for your Help

This topic has been closed for replies.
Correct answer Robert at ID-Tasker

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MasterSpread.html

 

name

String

readonly

The name of the MasterSpread.

 

InDesign Template - INDT file - is not MasterSpread.

 

You are rather looking for:

baseName

String

read/write

The name of the master spread.

or

namePrefix

String

read/write

The prefix of the master spread name.

 

2 replies

rob day
Community Expert
February 23, 2024

Hi @Rosalyparis , Also, I‘m not sure why you are adding and removing the textFrame—is this a ChatGPT script?

 

Try this:

if (app.documents.length > 0) {
    var doc = app.activeDocument;
    for (var i = 0; i < doc.masterSpreads.length; i++) {
        var masterSpread = doc.masterSpreads[i];
        var largeur = masterSpread.pages[0].bounds[3] - masterSpread.pages[0].bounds[1];
        var hauteur = masterSpread.pages[0].bounds[2] - masterSpread.pages[0].bounds[0];
        masterSpread.baseName = "Gabarit_" + Math.round(largeur) + "x" + Math.round(hauteur);
    }
    alert("Le renommage des gabarits est terminé !");
} else {
    alert("Aucun document ouvert. Veuillez ouvrir un document InDesign.");
}

 

Rosalyparis
New Participant
February 23, 2024

yes it was a script generate with CHAT GPT

Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Brainiac
February 23, 2024

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MasterSpread.html

 

name

String

readonly

The name of the MasterSpread.

 

InDesign Template - INDT file - is not MasterSpread.

 

You are rather looking for:

baseName

String

read/write

The name of the master spread.

or

namePrefix

String

read/write

The prefix of the master spread name.