7 Replies Latest reply on Jul 8, 2009 12:47 AM by Thomas B. Nielsen

    Help with paragraphStyleGroups

    johnBking78

      I have been using the code below (René Mølsted helped me with this) to change one style to another, but now need to reference a style within a group, and have given it a go (see below) but just cant get it to work, can anyone help?

       

      Many thanks

       

      app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
      app.changeTextPreferences.appliedParagraphStyle = "HEAD_24_36pt_45";
      app.documents[0].changeText();
      

       

      This is one of the may attempts?

      app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
      app.changeTextPreferences.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("HEAD AND BODY PARA STYLES").paragraphStyles. = "HEAD_24_36pt_45");  
      app.documents[0].changeText();
      

       

      Original script

      #target indesign;
      
      app.findTextPreferences = app.changeTextPreferences = null;
      app.findChangeTextOptions.includeFootnotes = true;
      app.findChangeTextOptions.includeHiddenLayers = true;
      app.findChangeTextOptions.includeMasterPages = true;
      
      try {
           app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
           app.changeTextPreferences.appliedParagraphStyle = "00 - Chapter Title";
           app.documents[0].changeText();
           
           /*Clear the find/change preferences after the search.*/
           app.findTextPreferences = NothingEnum.nothing;
           app.changeTextPreferences = NothingEnum.nothing
      }  catch(err){}
      
      try {
           app.findTextPreferences.appliedParagraphStyle = "Heading 2";
           app.changeTextPreferences.appliedParagraphStyle = "01 - A Heads";
           app.documents[0].changeText();
           
           /*Clear the find/change preferences after the search.*/
           app.findTextPreferences = NothingEnum.nothing;
           app.changeTextPreferences = NothingEnum.nothing
      } catch(err){}
      
      try {
           app.findTextPreferences.appliedParagraphStyle = "Heading 3";
           app.changeTextPreferences.appliedParagraphStyle = "02 - B Heads"
           app.documents[0].changeText();
           
           /*Clear the find/change preferences after the search.*/
           app.findTextPreferences = NothingEnum.nothing;
           app.changeTextPreferences = NothingEnum.nothing
      } catch(err){}
      
      try {
           app.findTextPreferences.appliedParagraphStyle = "Number 8";
           app.changeTextPreferences.appliedParagraphStyle = "paraNumbered8";
           app.documents[0].changeText();
           
           /*Clear the find/change preferences after the search.*/
           app.findTextPreferences = NothingEnum.nothing;
           app.changeTextPreferences = NothingEnum.nothing
      } catch(err){}
      
      

        • 1. Re: Help with paragraphStyleGroups
          Thomas B. Nielsen Level 3

          app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
          app.changeTextPreferences.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("HEAD AND BODY PARA STYLES").paragraphStyles.item("HEAD_24_36pt_45");
          app.documents[0].changeText();

          • 2. Re: Help with paragraphStyleGroups
            johnBking78 Level 1

            Hi Thomas,

             

             

            I gave that a go, but it did not work? if you have any other ideas that would be great, I am a bit new to this, so I will keep experimenting with different combinations.

             

            Many thanks

            • 3. Re: Help with paragraphStyleGroups
              Thomas B. Nielsen Level 3

              I do get a paragraph style with this method, ofc only if the group and para style is named as the scripts asumes.

              I are on CS3.

               

              What happend? It did not work is not easy to give you good suggestions on :-)

              • 4. Re: Help with paragraphStyleGroups
                johnBking78 Level 1

                Hi,

                 

                I'm using CS3, and when I run this script (on a mac) it does run, but no errors at all, but nothing changes? the styles don't change? I have setup a basic style group called test, to test it was not me getting the names wrong my script looks like this:

                 

                 

                #target indesign;
                app.findTextPreferences = app.changeTextPreferences = null;
                app.findChangeTextOptions.includeFootnotes = true;
                app.findChangeTextOptions.includeHiddenLayers = true;
                app.findChangeTextOptions.includeMasterPages = true;
                
                try {
                
                app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
                app.changeTextPreferences.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("test").paragraphStyles.item("test1");
                app.documents[0].changeText();
                     
                     /*Clear the find/change preferences after the search.*/
                     app.findTextPreferences = NothingEnum.nothing;
                     app.changeTextPreferences = NothingEnum.nothing
                }  catch(err){}
                

                 

                 

                I have created a simple style group called test, with a style called test1?

                 

                This dose work if there is no style group:

                 

                 

                app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
                app.changeTextPreferences.appliedParagraphStyle = "test1";
                app.documents[0].changeText();
                

                 

                 

                 

                Thank you for you help!

                 

                 

                Kind Regards,

                 

                 

                Adam

                • 5. Re: Help with paragraphStyleGroups
                  Thomas B. Nielsen Level 3

                  #target indesign;
                  var myDocument = app.activeDocument;
                  var myFindStyle = myDocument.paragraphStyles.item("Heading 1 NoNumber");

                   

                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing

                   

                  app.findChangeTextOptions.includeFootnotes = true;
                  app.findChangeTextOptions.includeHiddenLayers = true;
                  app.findChangeTextOptions.includeMasterPages = true;

                   

                  app.findTextPreferences.appliedParagraphStyle = myFindStyle;
                  app.findTextPreferences.findWhat= "";

                   

                  app.changeTextPreferences.appliedParagraphStyle = myDocument.paragraphStyleGroups.item("test").paragraphStyles.item("test1");
                  app.documents[0].changeText();
                      
                  /*Clear the find/change preferences after the search.*/
                  app.findTextPreferences = NothingEnum.nothing;
                  app.changeTextPreferences = NothingEnum.nothing

                  • 6. Re: Help with paragraphStyleGroups
                    johnBking78 Level 1

                    That works a treat!! Thank you very much!

                     

                     

                    I have a few more styles in groups and have duplcated this script one after another, to find the other styles, this works well, but is it ok to do that?

                     

                     

                    Many thanks again!!!

                    • 7. Re: Help with paragraphStyleGroups
                      Thomas B. Nielsen Level 3

                      I would think so, "if it gets the job done..." :-)