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

Replace styles script

Return to Member Forum

  • Author
    Posts
    • #61631
      gbwells
      Member

      I'm wondering if anyone has ever seen a script that would replace specifically named styles with other specifically named styles.

      Essentially, we have a series of styles in a template document. We're creating a new template document that is using style groups instead of a prefix in the style name. When we pull in content from old files into the new template, it brings in the old styles. There are quite a few styles (both para and char) and it takes a while to delete styles and replace with new. What we'd like to be able to do is map styles in a script to replace old styles with new styles.

      it would also be nice to be able to do the same with swatches in the palette. We have swatches called “Accent_01.” if people move pages in, it takes what you had colored “Accent_01” in the original document and applies “Accent_01” in the new document. But if you copy/paste items instead, you now get swatches from the original document named “Accent_01 1” and “Accent_01 2”. It would be nice to replace anything that says “Accent_01 $” (with a space after 01) with “Accent_01” (and so on).

      so, does anyone know of anything that exists out there? or something that is similar that we may be able to repurpose without having to start from scratch?

    • #61643
      Anonymous
      Inactive

      actually i just dug up something to do that very thing. you can just replace your styles/style groups over “title” and “Title” and my style group. For context, this one finds “Title” (no style group), replaces it with “title” (Catalog Styles) and deletes “Title”

      var myDocument = app.activeDocument;

      if (myDocument.characterStyles.item(“Title”) != null) {

      if (myDocument.characterStyleGroups.item(“Catalog Styles”). characterStyles.item(“title”) != null) {

      myDocument.characterStyles.item(“Title”).remove(myDocument.characterStyleGroups.item(“Catalog Styles”). characterStyles.item(“title”));

      presumably you could do the same thing by replacing the characterStyles.item with something from this page, don't have indesign at home to test it out though:

      https://indesignscriptingrefere…..ches-3.htm

      Also, if Jongware wrote me another handy script that just removes all the styles that aren't in an array you specify in the script:

      https://creativepro.com/for…..aph-styles

      hope that helps

    • #61664
      gbwells
      Member

      that really did help. i had a few minor issues figuring out some code structure (i'll admit, i'm a complete newbie to scripting and it's a good thing your sample code was relatively straightforward to follow).

      so i have my basic script done–with a whole lot of styles to add on both sides, we have a huge style list. but my test script worked great.

      thanks again!

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