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

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

Community Beginner ,
Feb 23, 2024 Feb 23, 2024

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

TOPICS
Feature request , Scripting , UXP Scripting
372
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

LEGEND , Feb 23, 2024 Feb 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.

 

Translate
LEGEND ,
Feb 23, 2024 Feb 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.

 

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
Community Expert ,
Feb 23, 2024 Feb 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.");
}

 

Screen Shot.png

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
Community Beginner ,
Feb 23, 2024 Feb 23, 2024

yes it was a script generate with CHAT GPT

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
Community Beginner ,
Feb 23, 2024 Feb 23, 2024
LATEST

Withe the response of robert Tkaczyk Chat GPT create a new script thuis new script was OK 

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