1

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
    I didn't quite understand. How much more automatic can you get than the delete method? ...the delete method, that automatically replaces all occurences of one paragraph style with another... – Joonas Jul 8 '15 at 6:05
  • When you delete a paragraph style you also need to reassign a new style to take its place. I am looking to automate the process of deleting style-1 and then assigning the text (that was until now styled as style-1) to style-2. So yeah that's at least 4 mouse-clicks reduced right there. Besides, in my workflow, I'm gonna have to repeat this process for a whole bunch of styles so yeah the automation is justified. Let's focus on "how" rather than "why." Thanks. – TheLearner Jul 8 '15 at 8:46
  • 2
    OP's quite often want one thing but actually need something else. When someone asks about automating a seemingly automatic function in a software, I'd rather figure out why, than to just blindly do as master says. – Joonas Jul 8 '15 at 13:52
  • Never mind. I figured it out and posted my solution for others. Thanks for your time. Cheers. – TheLearner Jul 8 '15 at 18:35
1

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.

0

You can use this script.

    var myDoc = app.activeDocument;  

try {
myDoc.paragraphStyles.item("Old Still").remove("New Still");
} catch(e) {}

İf you want to replace more than one style just duplicate this code and change style names.

try {
    myDoc.paragraphStyles.item("Old Still").remove("New Still");
    } catch(e) {}
  • 2
    This solution is already included in the accepted answer, please don't just repeat information. There's plenty of unanswered questions that could benefit from your time. – Luciano Apr 5 '18 at 14:42
  • Well, there is additional feature in the code I wrote. İf paragraph style doesn't exist in documents, script will give error and stop working. İn my version script will ignore any error and try to replace existing paragraph styles. – Ahmet Samsa Apr 8 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.