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

A small point, but you don't need this:

 

doc.TextSelection = textRange;

 

This was used so that you could see each range of text highlighted while you were testing it on a single paragraph, but it is not necessary in the finished script.

 

Also, allow an old man to scold you for your approach. I had my original code set up to work on the paragraph containing the insertion point. This is a useful approach because you can test and troubleshoot on a single paragraph. Then, once everything is working on that paragraph, you can expand the script to work on multiple paragraphs, documents, etc. But you went ahead and expanded the script before you got it working on the single paragraph. This makes it difficult to know exactly where the problem is. So, at the risk of being tedious, let's go back to the original code and a paragraph containing the insertion point. I have modified the code slightly and put it into a function.

 

#target framemaker

var doc = app.ActiveDoc;
var pgf = doc.TextSelection.beg.obj;
cleanPgf (pgf, doc);

function cleanPgf (pgf, doc) {

    var textList = pgf.GetText (Constants.FTI_CharPropsChange);    var fontName;     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));            fontName = (doc.GetTextPropVal(textRange.beg, Constants.FP_FontPlatformName).propVal.sval);            if (/symbol/i.test (fontName) === true) {                alert (fontName);            }            begOffset = endOffset;        }    }    textRange = new TextRange(new TextLoc (pgf, begOffset), new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET));    fontName = (doc.GetTextPropVal(textRange.beg, Constants.FP_FontPlatformName).propVal.sval);    if (/symbol/i.test (fontName) === true) {        alert (fontName);    }
}

 

When you run this in a paragraph containing Symbol, you should see the alert displaying the font name. You can replace the alert lines with calls to another function:

 

function applyCharFmt (textRange, charFmtName, doc) {    var charFmt = doc.GetNamedCharFmt (charFmtName);    if (charFmt.ObjectValid()) {        doc.SetTextProps (textRange, charFmt.GetProps());    }

}

 

The problem in your code was this line:

 

props = doc.GetProps(CharFmtId);

 

which should have been:

 

props = CharFmtId.GetProps();

 

I use a slightly different syntax with the same result. Once you get it working on a single paragraph, you can safely expand it to work on all of the paragraphs in the document.

 

--Rick


Viewing all articles
Browse latest Browse all 3715


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