4 Replies Latest reply on May 4, 2010 11:23 PM by Roy Marshall

    [JS] [CS3 onwards]

    Roy Marshall Level 1



      I am needing to include in my script the ability to change paragraph styles, but the target style is within a paragraph style folder.


      My current code for a folderless structure is this:

      if(myStory.paragraphs[ii].appliedParagraphStyle.name == "PRO - Product Heading")


           myStory.paragraphs[ii].appliedParagraphStyle =  "PRO - Product Heading " + myColour;


      I know how to get the folder name of a style by using the parent property, but how to apply with that parent property is where I am stuck.


      I had thought (and foolishly tried)  myStory.paragraphs[ii].appliedParagraphStyle =  "Pro:PRO - Product Heading " + myColour; thinking that "Pro:" would look for a style folder, but that didn't work.


      Any help as always would be greatfully received.





        • 1. Re: [JS] [CS3 onwards]
          Roy Marshall Level 1

          ...and any suggestions on how to paste code without the mess up above would be good too!

          • 2. Re: [JS] [CS3 onwards]
            [Jongware] Most Valuable Participant

            The problem here is that JS silently looks up things if it cannot apply your current command. In the case of setting a paragraph style, you can feed it a string, but that actually gets checked against the current list of paragraph styles, and it's the style itself that gets used.


            This ought to work:


            myGroup = app.activeDocument.paragraphStyleGroups.item("PRO");
            myDirectLinkToAStyle = myGroup.paragraphStyles.item("PRO - Product Heading :+color);
            .. stuff here ..
            myStory.paragraphs[ii].appliedParagraphStyle = myDirectLinkToAStyle;


            Untested, untried, etc. You know the drill.


            (I always type a post in full before daring to click any of the horrendous Jive formatting buttons. I find it inexplicably difficult to edit code with that weird and unpredictably-behaving Code Formatting thingamajig. Before not-that-long-ago, I simply switched to HTML mode and injected my edits straight into the correct place, but -- oh sadness! -- New and Improved Jive seems to bracket each and every single character with some "function (bladiblah) (release(whatever))" crap code.

            Since the Adobe programmers seem to have grown a liking to Flash, WRITE A FLASH EDITOR for the forums! Or simply buy one -- I've seen a-plenty online Flash editors with lotsa nice features. Either way, get rid of this Jive bull.)

            • 3. Re: [JS] [CS3 onwards] Using Style sheets within Folders
              Roy Marshall Level 1

              Sorry, I didn't title this thread correctly.  Now sorted, and linked to via a new thread. If only I could edit the title but alas no

              • 4. Re: [JS] [CS3 onwards]
                Roy Marshall Level 1

                Hi Jongware


                Thanks heaps.  I had to adapt the script slightly as I couldn't pass the style name in the way you suggested, I needed to construct a string and pass that instead:


                myParaGroup = app.activeDocument.paragraphStyleGroups.item("Pro");

                myNewStyleString = "PRO - Product Heading " + myColour;

                myDirectLinkToAStyle = myParaGroup.paragraphStyles.item(myNewStyleString);

                myStory.paragraphs[ii].appliedParagraphStyle = myDirectLinkToAStyle;


                Anyway, thanks again, you have made my client very happy!