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

Re: Adding Character Tag based on used Font Family

$
0
0

In my opinion, this is one of the most difficult aspects of scripting FrameMaker to understand: dealing with text items. But it is very powerful, because you can break down a paragraph by every single character property change. Here is basically what you have to do. First, start with a single paragraph with some character property changes; in your case, apply the Symbol font to some of the text. Then, put your cursor in the paragraph and run the code below. You will see that it goes through and highlights each range of text that is uniquely formatted and displays an alert box.

 

#target framemaker

var doc = app.ActiveDoc;
var pgf = doc.TextSelection.beg.obj;

var textList = pgf.GetText (Constants.FTI_CharPropsChange);

var begOffset = 0, endOffset = 0, textRange;
for (var i = 0; i < textList.length; i += 1) {    endOffset = textList[i].offset;    if (endOffset  > begOffset) {        textRange = new TextRange(new TextLoc (pgf, begOffset), new TextLoc (pgf, endOffset));        doc.TextSelection = textRange;        alert (textRange);        begOffset = endOffset;    }
}
textRange = new TextRange(new TextLoc (pgf, begOffset), new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET));
doc.TextSelection = textRange;
alert (textRange);

 

Of course, you are not done, because you have to test the properties at the beginning of each text range. But a lot of the work is done with this code, which could (should) be generalized into a function.

 

--Rick


Viewing all articles
Browse latest Browse all 3715

Trending Articles



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