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

Script find/change paragraph style

Explorer ,
Apr 29, 2020 Apr 29, 2020

Hello i'am looking for a script that find for example a paragraph style 'Header' and change that to paragraph style 'Header 2'

Can somebody help me?

 

Kind regards,

Patrick

TOPICS
Scripting
6.1K
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

Community Expert , Apr 29, 2020 Apr 29, 2020

One more time. Sorry, not enough coffee today: 

 

var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
   if (allPars[i].appliedParagraphStyle.name == "Header") {
      allPars[i].appliedParagraphStyle = "Header 2";
   }
}

 

If you want to find and change more paragraph styles, you can add additional if statements within the loop using the same structure as above. There are other ways to, like

...
Translate
Community Expert ,
Apr 29, 2020 Apr 29, 2020

If you're not aware, you can use Find/Replace using the Find Format and Change Format in InDesign itself: 

Screen Shot 2020-04-29 at 12.40.49 PM.png

 

Otherwise, you'll need to specify how you're finding your paragraphs in your script. Here's one that would iterate through every paragraph in the doc and check, but it's not very efficient. 

 

var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
   if (allPars[i].appliedParagraphStyle.name == "Header") {
      allPars[i].appliedParagraphStyle = "Header 2";
   }
}

 

 

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
Explorer ,
Apr 29, 2020 Apr 29, 2020

The cript above is not working.

I have more paragraph styles. Is there also i way with find/change by list that i can change the txt file.

For example:

 
text {findParagraphStyle:"Header"} {appliedParagraphStyle:"Header 2"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
 
 
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 ,
Apr 29, 2020 Apr 29, 2020

Oops, made a quick fix. Try again. 

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
Explorer ,
Apr 29, 2020 Apr 29, 2020

Where can i find the fix?

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 ,
Apr 29, 2020 Apr 29, 2020

In the original code, repasted here: 

 

var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
   if (allPars[i].appliedParagraphStyle.name == "Header") {
      allPars[i].appliedParagraphStyle = "Header 2";
   }
}

 

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
Explorer ,
Apr 29, 2020 Apr 29, 2020

It's still not working. The script change nothing.Schermafbeelding 2020-04-29 om 22.20.22.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 Expert ,
Apr 29, 2020 Apr 29, 2020

One more time. Sorry, not enough coffee today: 

 

var allPars = app.activeDocument.textFrames.everyItem().paragraphs.everyItem().getElements();
alert(allPars.length);
for (var i = 0; i < allPars.length; i++) {
   if (allPars[i].appliedParagraphStyle.name == "Header") {
      allPars[i].appliedParagraphStyle = "Header 2";
   }
}

 

If you want to find and change more paragraph styles, you can add additional if statements within the loop using the same structure as above. There are other ways to, like using Find/Replace scripting or modifying Find Change By List.  

 

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
Enthusiast ,
May 01, 2020 May 01, 2020
LATEST

Hi,

Were you aware that you can do this manually in the paragraph styles menu? When you delete a style you have the option of replacing it with another. Just make sure the new style is not based on the original style. Here is how you would do it with AppleScript:

tell application "Adobe InDesign 2020"
tell document 1

set oldStyle to paragraph style "Header"

set newStyle to paragraph style "Header2"

delete oldStyle replacing with newStyle

end tell

end tell

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