6 Replies Latest reply on Dec 10, 2013 11:26 AM by omansaud

    from paragraph Style to "New Hyperlink Destination"

    omansaud

      Dear InDesign Experts

       

      Please help me to find a way or Script to add all headings of specific paragraph style to "New Hyperlink Destination....(Text Anchor)"

      and ... is there any automation for such a task?

       

      Thank you in advance

        • 1. Re: from paragraph Style to "New Hyperlink Destination"
          Green4ever Level 3

          Hi Saud,

           

          Try the below script.

           

           

          var activeDoc = app.activeDocument;
          
              app.findGrepPreferences = NothingEnum.nothing;
              app.changeGrepPreferences = NothingEnum.nothing;
          
          app.findGrepPreferences.appliedParagraphStyle = "XXXX";//Give your paragraph Style name here
          var foundRefList = activeDoc.findGrep();
          
              app.findGrepPreferences = NothingEnum.nothing;
              app.changeGrepPreferences = NothingEnum.nothing;
          
          var myCount =0;
          var foundListLength = foundRefList.length;
          for (var j = 0; j<foundListLength; j++){
              var myParas = foundRefList[j].paragraphs;
              var myParaLength = myParas.length;
              for (var i = 0; i<myParaLength; i++){
                  var myText  = myParas[i].texts[0];
                  app.select(myText);
                  var myId = j+"_"+(i+1);
                  var myHyperlinkCitDestination = activeDoc.hyperlinkTextDestinations.add(myText, {name: myId});
                  myCount++;
                  }
              app.select(NothingEnum.nothing);
              alert("Process Completed\n"+myCount+" destinations added");
              }
          

           

          p.s: I've not tested it, please check this at your end and let me know.

           

          ~Green4ever

          1 person found this helpful
          • 2. Re: from paragraph Style to "New Hyperlink Destination"
            omansaud Level 1

            its perfect Green4ever,

            Thank you very much

             

            this what i was looking for, but the only thing is .. can the list be the same as what been found in paragraph style, in aother meaning if found "Green" in the specified Paragraph style so the destination name will be also "Green" .

             

            THank you again ~Green4ever

            • 3. Re: from paragraph Style to "New Hyperlink Destination"
              Green4ever Level 3

              The names should be unique. If you choose same name for the 2nd para (destination) it will throw error.

               

              But you can add your text "Green" at the end/start of each of name. see the e.g. below.

               

              var myId = j+"_"+(i+1)+"Green";

               

              ~Green4ever

              • 4. Re: from paragraph Style to "New Hyperlink Destination"
                omansaud Level 1

                thank you Mr. Green4ever for your helful support.

                 

                I Try to run, its works but the result is numbers only eg:

                0_1

                1_1

                2_1

                 

                where i wish to get insted of 1, the actual text in paragraph. is it possible?

                example:

                0_USA

                1_UK

                2_France

                 

                where USA, UK, FRance is in paragragraph Style of XXXX

                • 5. Re: from paragraph Style to "New Hyperlink Destination"
                  Green4ever Level 3

                  Try this

                   

                   

                  var activeDoc = app.activeDocument;
                  
                      app.findGrepPreferences = NothingEnum.nothing;
                      app.changeGrepPreferences = NothingEnum.nothing;
                  
                  app.findGrepPreferences.appliedParagraphStyle = "XXXX";//Give your paragraph Style name here
                  var foundRefList = activeDoc.findGrep();
                  
                      app.findGrepPreferences = NothingEnum.nothing;
                      app.changeGrepPreferences = NothingEnum.nothing;
                  
                  var myCount =0;
                  var foundListLength = foundRefList.length;
                  for (var j = 0; j<foundListLength; j++){
                      var myParas = foundRefList[j].paragraphs;
                      var myParaLength = myParas.length;
                      for (var i = 0; i<myParaLength; i++){
                          var myText  = myParas[i].texts[0];
                          app.select(myText);
                          var myId = j+"_"+(i+1)+"_"+myText.contents;
                          var myHyperlinkCitDestination = activeDoc.hyperlinkTextDestinations.add(myText, {name: myId});
                          myCount++;
                          }
                      app.select(NothingEnum.nothing);
                      alert("Process Completed\n"+myCount+" destinations added");
                      }
                  

                   

                  ~Green4ever

                  • 6. Re: from paragraph Style to "New Hyperlink Destination"
                    omansaud Level 1

                    Thank you so much

                    i made little modification i works perfectley.

                     

                     

                    Thans again Mr. Grren4ever