Highlighted

Script find/change paragraph style

Explorer ,
Apr 29, 2020

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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.  

 

Topics

Scripting

Views

639

Likes

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

Script find/change paragraph style

Explorer ,
Apr 29, 2020

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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.  

 

Topics

Scripting

Views

640

Likes

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

Copy link to clipboard

Copied

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";
   }
}

 

 

Likes

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

Copy link to clipboard

Copied

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}
 
 

Likes

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
Reply
Loading...
Adobe Community Professional ,
Apr 29, 2020

Copy link to clipboard

Copied

Oops, made a quick fix. Try again. 

Likes

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

Copy link to clipboard

Copied

Where can i find the fix?

Likes

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
Reply
Loading...
Adobe Community Professional ,
Apr 29, 2020

Copy link to clipboard

Copied

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";
   }
}

 

Likes

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

Copy link to clipboard

Copied

It's still not working. The script change nothing.Schermafbeelding 2020-04-29 om 22.20.22.png

Likes

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
Reply
Loading...
Adobe Community Professional ,
Apr 29, 2020

Copy link to clipboard

Copied

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.  

 

Likes

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
Reply
Loading...
Enthusiast ,
May 01, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...