0 Replies Latest reply on Dec 11, 2013 12:25 AM by omansaud

    Hyperlink paragraph Style text to matched text in hyperlinkTextDestinations

    omansaud

      Hello,

       

       

      i want to connenct text in specific ParagraphStyle then search a match in hyperlinkTextDestinations, if matching found then hyperlink

       

      i could find the matching "see //*******" but i cannot hyperlink them.

       

      please help.

       


       

       

      current code:

       

       

       

      String.prototype.lpad = function(padString, length) {
          var str = this;
          while (str.length < length)
              str = padString + str;
          return str;
      }
      
      
      var MyStyle="look_text" // This is to select the ParagraphStyle
      activeDoc = app.activeDocument; // The Action on Current Opened Document in Indesign
      
      
      app.findGrepPreferences = NothingEnum.nothing;     //clearing the  preferences object  to make sure the settings from previous searches have no effect on the search. 
      app.changeGrepPreferences = NothingEnum.nothing; //clearing the  preferences object  to make sure the settings from previous searches have no effect on the search
      app.findGrepPreferences.appliedParagraphStyle = MyStyle ;//Target  paragraph Style name 
      
      
      var foundRefList = activeDoc.findGrep();
      var myCount =0;
      var foundListLength = foundRefList.length;
      for (var j = 0; j<foundListLength; j++){//1
      
              app.findGrepPreferences.appliedParagraphStyle = MyStyle ;//Selecting desired paragraph Style name
              var foundRefList = activeDoc.findGrep();
              var myParas = foundRefList[j].paragraphs;
              var myParaLength = myParas.length;
              for (var i =0; i<myParaLength; i++){//2
                  var MySelectedText  = myParas[i].texts[0];
                  app.select(MySelectedText);
                  myId = myId.replace(/^\s+|\s+$/g,'');
                  myCount++;
                  if (myId.length > 1){//3
                      var myFound = activeDoc.hyperlinkTextDestinations.itemByName(myId)        
                          if (activeDoc.hyperlinkTextDestinations.item(myId).isValid) {
                               // var AddItem= activeDoc.hyperlinkTextDestinations.add(myId);                
                               //var AddItem = activeDoc.hyperlinkTextDestinations.add(myId[i]);
                              alert ( "The Selected text " + myId +" been found in Destination "+"\n"+myFound.name );
      
      
                             }
                           else   
                              alert(MySelectedText.contents+" No match")//myFound.name+" is found in hyperlinkTextDestinations");
                  }
              }
          app.select(NothingEnum.nothing);
          }