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

Script to automatically rename Paragraph Styles based on content

Explorer ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

I am creating a template for future documents in a company I work for. There will be about 50-60 Paragraph styles based on various fonts and sizes etc. At the moment I am mannually namings these

Title Font Name Weight Size Justification Colour
"H4 Space Grotesk Bold 30 Centre White"

Say I decide to change the font size to 24, I would like to be able to update all the names that have 30 in them to 24. 

Is this possible through scripting?

TOPICS
Scripting

Views

459

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 , Sep 02, 2022 Sep 02, 2022

Assuming the point size is always offset by spaces and is the only standalone number in the name: 

 

var aps = app.activeDocument.allParagraphStyles;
var i = aps.length;
while(i--) {
   aps[i].name = aps[i].name.replace(/ ^\d+ /g," " + aps[i].pointSize + " ");
}

 

 

 

This also assumes that you've already change the point size in the style. If you wanted to change the point size with a prompt it'd be: 

 

 

var aps = app.activeDocument.allParagraphStyles;
var i = aps.length;
var p1 = prompt("old 
...

Votes

Translate

Translate
Community Beginner ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

If you associate your styles with a reference style using the "based on" property of a text style, you could change all of the derivated text styles in a blink without scripting. But it would change the title attributes for sure. 

For that, indeed a script is necessary and yet it could be a bit challenging due to your naming convention. For exemple, if you change justification from center to letf justified, the script should change the name accordingly. And for that the script would need to know exactly what to change.

Is there any logic beyond your naming convention?

Loic

 

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
Explorer ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Those won't change, the only thing that would change is font size. I will have bold/regular centre left all done but there would be too many font sizes.

I usually start an A4 document with 18 heading, 14 subheading, 11 body, 8 subscript. But say the document is an A1 information poster, the font would be larger. So I don't want to go in and mannually change that. 

The naming convention is really to make sure what I am selecting is right, I have ADHD so I kind of need to spell it out for myself sometimes. 

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 ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

LATEST

Assuming the point size is always offset by spaces and is the only standalone number in the name: 

 

var aps = app.activeDocument.allParagraphStyles;
var i = aps.length;
while(i--) {
   aps[i].name = aps[i].name.replace(/ ^\d+ /g," " + aps[i].pointSize + " ");
}

 

 

 

This also assumes that you've already change the point size in the style. If you wanted to change the point size with a prompt it'd be: 

 

 

var aps = app.activeDocument.allParagraphStyles;
var i = aps.length;
var p1 = prompt("old point size");
var p2 = prompt("new point size");
while(i--) {
   if (aps[i].pointSize == Number(p1)) {
       aps[i].pointSize = Number(p2);
       aps[i].name = aps[i].name.replace(p1, p2);
   }
}

 

 

Haven't tested yet as  I have to take the kids to school

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