Quantcast
Channel: Adobe Community: Message List - FrameMaker Scripting
Viewing all articles
Browse latest Browse all 3715

Re: How to apply hypertext marker to text with specific character tag

$
0
0

I get it. Nice idea, but complicated.

 

In your code above, you are not actually finding anything; rather you are just retrieving the character format object from the document. To actually find a location where the format is applied, you would need something like this:

 

 

 

      var findParams = AllocatePropVals(2);
     
      findParams[0].propIdent.num = Constants.FS_FindCharTag;   
      findParams[0].propVal.valType = Constants.FT_String;   
      findParams[0].propVal.sval = fmtName; 
     
      findParams[1].propIdent.num = Constants.FS_FindWrap;   
      findParams[1].propVal.valType = Constants.FT_Integer;   
      findParams[1].propVal.ival = false; 
 
      var textRange = new TextRange();
      textRange.beg.obj = textRange.end.obj = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf; 
      textRange.beg.offset = textRange.end.offset = 0; 
      doc.TextSelection = textRange;

      textRange = doc.Find(textRange.beg, findParams);

 

 

Then, with a successful find, you could add the marker like this, where I included the code to apply the character format:

 

      var charFmt = doc.GetNamedCharFmt("Link");

 

      var marker = doc.NewAnchoredMarker(textRange.beg);

      var markerRange = new TextRange(marker.TextLoc, marker.TextLoc);

      markerRange.end.offset++;

      doc.SetTextProps(markerRange, charFmt.GetProps());

 

You would also need to set the marker type (Hyperlink) and the marker text (goto something). You would need your getText() method to finish that last part.

 

It gets complicated when you want to loop through a whole doc. You can put Find into a loop, but it seems that every time you modify the doc with a new marker, it resets the Find action and you end up finding and adding markers endlessly. You could do all the Finds first and put the results in an array, but the problem with that is you could mess up a text range in the array by adding a marker earlier in the same paragraph.

 

I experimented some but ran out of time. I was thinking of a routine to first delete all markers out of the whole doc, then add them back with a second recursive search. But I didn't come up with anything simple and like I said, I'm out of time for now. Perhaps you can experiment with this some more with the ideas above and come back with an idea on how the routine should work. I hope this helps.

 

Russ


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>