0 Replies Latest reply on Oct 1, 2010 5:58 AM by IowaBoy9

    can you add appliedCharStyle while creating hyperlink

    IowaBoy9

      I noticed that the menu to create a hyperlink manually now has an option to apply a character style to the text source. Is it possible to apply a character style while adding a hyperlink in JavaScript? I am using findGrep() to iterate through a large document adding hyperlinks to found text. I currently use changeGrepPreferences (see bottom of script below). But I thought it might be faster to use the new feature.

       

      If it is possible to do apply the character style in while adding the hyperlink, how would I do it? My attempt below does not work.

       

      var myDoc = app.activeDocument;

      var charastyles = myDoc.characterStyles.everyItem().name;

      app.changeGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences.findWhat = '[MAP][ELO][PR]S:';

       

      var foundCodes = myDoc.findGrep()

       

      for (var i = foundCodes.length - 1; i >= 0; i--) {

       

       

      switch (foundCodes[i].contents)

          {

          case "MEPS:": 

       

      var _charStyle = app.activeDocument.appliedCharacterStyle = "Hyperlink";  //

       

      var _hlinkSource = app.activeDocument.hyperlinkTextSources.add(foundCodes[i]);

          var _destination = app.activeDocument.hyperlinkURLDestinations.add("http://www.meps.com");

          app.activeDocument.hyperlinks.add(_hlinkSource, _destination, _charStyle) // <----this works without the _charStyle

       

      break;

       

      //three more cases go here

       

      alert ("Not a good selection."); exit ()

          }

       

       

      }

      //app.changeGrepPreferences.appliedCharacterStyle = 'Hyperlink'; <--- I have been using these lines to change the character style

      //myDoc.changeGrep();

      app.changeGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences = NothingEnum.nothing;

      alert ("Done")