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

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

Community Beginner ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

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

Views

204

Translate

Translate

Report

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

Community Expert , 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.

 

Votes

Translate

Translate
Community Expert ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

yes it was a script generate with CHAT GPT

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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