Indesign script to replace paragraph style


Question

I am using ID CC 2014 on a Mac and there's a huge file with several hundred pages where I need to delete a certain paragraph style replacing it with another. Say there's a para style called "style-1". When I delete it from the para styles panel, it asks me to provide another style to take its place for pieces of text currently styled as "style-1". Here, I add, say, "style-2" to take its place. Is there any way to automate the process using a script? I tried studying the FindTextPreference JS class but it doesn't seem to have the properties we might need in this case. Any tips?

1
1
7/8/2015 4:35:00 AM

Accepted Answer

Okay, I finally figured out the answer myself and am posting it here for the benefit of others. The trick is to call the remove method of the ParagraphStyle class (more accurately, the paragraph style being removed). The syntax is:

Old_Style.remove(New_Style);

In this syntax, the New_Style argument is optional. Thus, for my example, the correct code would be:

var old = app.activeDocument.paragraphStyles.itemByName("style-1"); var new = app.activeDocument.paragraphStyles.itemByName("style-2"); old.remove(new);

More details on the ParagraphStyle class can be found at http://jongware.mit.edu/idcsjs5.5/pc_ParagraphStyle.html.

1
7/8/2015 8:56:00 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
^