4 Replies Latest reply on Aug 25, 2013 6:50 PM by Asher31

    How to show/say top level group/directory

    Asher31 Level 1

      So i have a script thanks to help from this forum for changing styles, but the one problem i still have is i don't know how to say or show the top level of a style (so one not in a group).

       

      Here is the code below, basically i just need to know what to put in instead of groupold/groupnew when the style i want to use is not in a group/folder. Thanks in advance.

       

       

       

       

      replaceStyle("Old", "H1", "new", "ActiviyH1");
      replaceStyle ("Old", "H2", "new","ActiviyH2")
      
      
      function replaceStyle(GroupOld , find, GroupNew, replace){
          try{
      var myDoc = app.activeDocument;
      importedStyle = myDoc.paragraphStyleGroups.item(GroupOld).paragraphStyles.item(find);
      ApplyStyle = myDoc.paragraphStyleGroups.item(GroupNew).paragraphStyles.item(replac e);
      importedStyle.remove(ApplyStyle);
          }
      catch(e){
          //alert (e)
          }
      }
      
      
        • 1. Re: How to show/say top level group/directory
          Peter Kahrel Adobe Community Professional & MVP

          I'm not sure if this is the answer you were looking for: if a style's parent is a document, it's a top-level style:

           

          if (myStyle.parent instanceof Document) {

             // myStyle is not in a style group

          }

           

          Peter

          • 2. Re: How to show/say top level group/directory
            Asher31 Level 1

            Where abouts would i put that, and what do i put in the "group" instead of the name of the group, or do i just leave it blank?

             

            And thanks heaps for taking to time to answer,

            Cheers

            • 3. Re: How to show/say top level group/directory
              Jump_Over Level 5

              Hi,

               

              Modify a function:

              function replaceStyle(GroupOld , find, GroupNew, replace){
                  try{
              var myDoc = app.activeDocument,
              importedStyle = myDoc.paragraphStyles.item(find),
              ApplyStyle = myDoc.paragraphStyles.item(replace);
              
              if (GroupOld) importedStyle = myDoc.paragraphStyleGroups.item(GroupOld).paragraphStyles.item(find) ;
              if (GroupNew) ApplyStyle = myDoc.paragraphStyleGroups.item(GroupNew).paragraphStyles.item(replace) ;
              
              importedStyle.remove(ApplyStyle);
                  }
              catch(e){
                  //alert (e)
                  }
              }
              

               

              you can call it like:

               

                   replaceStyle("", find, "", replace) or

                   replaceStyle(0, find, 0, replace) or

                   replaceStyle(undefined, find, undefined, replace)


              for top-level styles

               

              Jarek


              • 4. Re: How to show/say top level group/directory
                Asher31 Level 1

                Awesome thank you that worked a treat... just wondering how would i go about showing multilevel groups? Do i just add a '/' or '\'?

                 

                Also, and i know this is going a beyond the scope a little, how would i target an entire book to do this too? Is that even possible.

                 

                Thanks so much for taking the time to help me,

                Asher