Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to Replace Existing Paragraph Styles With New Style

Return to Member Forum

  • Author
    Posts
    • #1193813
      Art Hoffman
      Participant

      Hi All,

      I am working to replace all of our existing paragraph styles with new paragraph styles. The only change is changing Arial font to Roboto (thanks Google). Is there a way to do this en masse via script instead of one at a time? I found this and it looks like something that would work but I can’t get it to.

      var old1 = app.activeDocument.paragraphStyles.itemByName(“Model Number”);
      var new1 = app.activeDocument.paragraphStyles.itemByName(“Roboto Model Number”);
      old1.remove(new1);

      Even a script to just change the font in the existing paragraph styles would work. My script skills are pretty non-existent. Any help would be appreciated.

      Thank you!

    • #14323828

      If the paragraph styles are based on one specific paragraph style, then changing the font in this base style should do the job.

    • #14323822
      Peter Kahrel
      Participant

      Something like the following script changes Arial to Roboto only in paragraphs that use Arial. Dependencies (through basedOn) should carry over. A potential problem is font styles in Arial not present in Roboco, But if you use just, say, Regular and Italic you should be ok. The proof of the pudding…

      pstyles = app.activeDocument.allParagraphStyles;<br />
      for (i = 1; i < pstyles.length; i++) {<br />
        if (pstyles[i].appliedFont.fontFamily == 'Arial') {<br />
          pstyles[i].appliedFont = 'Roboco';<br />
        }<br />
      }
      

      P.

    • #14323820
      Peter Kahrel
      Participant

      You should leave out those
      tags. I couldn’t edit the code any longer after five attempts.

    • #14323818
      Art Hoffman
      Participant

      Aside from the typo (Roboto) this worked perfectly for changing the font! Now to adapt it for the other fonts.

      Where do I send the beer to?

      You guys here rock!

    • #14323787
      David Loveday
      Participant

      Hello Peter,
      I was very interested in the script that you created for Art Hoffman for changing fonts within a paragraph style – it worked for me. I have been looking for some time for something similar, but more in terms of a batch process, since nearly 1,000 documents are involved, spanning many different folders #d 0-20, with each folder having two sub-folders EN and FR. This would be very monotonous converting one at a time!!
      Any ideas, please?
      Thanks.
      David Loveday

    • #14323783
      Peter Kahrel
      Participant

      David — This script: https://www.kahrel.plus.com/indesign/batch_convert.html is a general batch processor. You can run a script with it as well, see the section ‘Run a script’ on that page.

      The script I posted above needs some changes before you can use it in the batch processor:

      (function () {
      var pstyles = app.activeDocument.allParagraphStyles;
      for (var i = 1; i < pstyles.length; i++) {
      if (pstyles[i].appliedFont.fontFamily == 'Arial') {
      pstyles[i].appliedFont = 'Roboco';
      }
      }

      }());

      Peter

    • #14323782
      Peter Kahrel
      Participant

      I’ll try again.

      (function () {
      var pstyles = app.activeDocument.allParagraphStyles;
      for (var i = 1; i < pstyles.length; i++) {
      if (pstyles[i].appliedFont.fontFamily == 'Arial') {
      pstyles[i].appliedFont = 'Roboco';
      }
      }
      }());

    • #14323778
      Jeremy Howard
      Participant

      This can also be easily accomplished by using the Find Font dialog (found under Type>Find Font).

      Once you have that dialog open, simply select the font that you want to replace, specify the replacement font and make sure you have the “Redefine Styles” option ticked on. Click “Replace” and all of your style sheets will be updated.

      No need for scripts on this one!

    • #14323769
      Peter Kahrel
      Participant

      For a single document or a small handful of documents your method would certainly the recommended method, Jeremy. But when you have 1,000 files…

    • #14323751
      David Loveday
      Participant

      Hello all,
      Thank you so much for you help. I will give it a try…

      Regards.

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
Forum Ads