Skip to main content
February 15, 2012
Answered

How do I use the find method to search for character and pgf format overrides?

  • February 15, 2012
  • 3 replies
  • 1836 views

I strongly suspect that I should be able to use the find method to search for paragraph and format overrides since those options are available in the find dialog box. However, due to Adobe's atrocious Extendscript documentation, I haven't been able to find the key pieces of information that I need. I did find these constants: 

  • Constants.FV_FindPgfFormatOverride
  • Constants.FV_FindCharacterFormatOverride

But there's literally no information about them. There's not even a definition, so I am actually just making an educated guess. However, I suspect that I somehow need to use these constant's in the Find method's parameters. Any ideas about how to do that?

This topic has been closed for replies.
Correct answer

You're right, there are still a few bugs to work out of the documentation, though it has already improved dramatically since I started working w/ Extendscript last summer.

Either of the constants you found should be set as the ival for a FindObject PropVal, e.g.,:

     var myDoc = app.ActiveDoc;

     var docStart = myDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ;

     var tloc = new TextLoc(docStart,0);

     var findParams = AllocatePropVals(1);

     findParams[0].propIdent.num = Constants.FS_FindObject;

     findParams[0].propVal.valType = Constants.FT_Integer;

     findParams[0].propVal.ival = Constants.FV_FindCharacterFormatOverride;

     myDoc.Find(tloc,findParams);

Depending on what you're trying to accomplish, you may also want to take a look at the FormatOverride property of the Doc, Pgf, and Element objects.

3 replies

frameexpert
Community Expert
Community Expert
February 6, 2020

I am not a big fan of using "Find" for these kinds of things. I would rather navigate the character property changes in a paragraph and isolate each unique range of text. Try clicking in one of your paragraphs and running this code:

 

#target framemaker

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

processPropertyChanges (pgf, doc);

function processPropertyChanges (pgf, doc) {

    var end = Constants.FV_OBJ_END_OFFSET - 1, begin = 0, textRange;
    
    var textList = pgf.GetText (Constants.FTI_CharPropsChange);
    for (var i = textList.length - 1; i >= 0; i -= 1) {
        begin = textList[i].offset;
        if (begin !== end) {
            textRange = new TextRange (new TextLoc (pgf, begin), new TextLoc (pgf, end));
            doc.TextSelection = textRange;
            alert ("test the beginning of the text range for the property you are looking for.");
            end = begin;
        }
    }
    if (end > 0) {
        textRange = new TextRange (new TextLoc (pgf,0), new TextLoc (pgf,end));
        doc.TextSelection = textRange;
        alert ("test the beginning of the text range for the property you are looking for.");
    }
}
www.frameexpert.com
frameexpert
Community Expert
Community Expert
February 6, 2020

Then you can do something like this (the CP.applyCharFmt function is not shown):

 

#target framemaker

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

function processPropertyChanges (pgf, doc) {

    var end = Constants.FV_OBJ_END_OFFSET - 1, begin = 0, textRange, charTag;
    
    var textList = pgf.GetText (Constants.FTI_CharPropsChange);
    for (var i = textList.length - 1; i >= 0; i -= 1) {
        begin = textList[i].offset;
        if (begin !== end) {
            textRange = new TextRange (new TextLoc (pgf, begin), new TextLoc (pgf, end));
            charTag = getCharacterFormatName (textRange, pgf, doc);
            if (charTag) {
                CP.applyCharFmt (textRange, charTag, doc);
            }
            end = begin;
        }
    }
    if (end > 0) {
        textRange = new TextRange (new TextLoc (pgf,0), new TextLoc (pgf,end));
        charTag = getCharacterFormatName (textRange, pgf, doc);
        if (charTag) {
            CP.applyCharFmt (textRange, charTag, doc);
        }
    }
}

function getCharacterFormatName (textRange, pgf, doc) {
    
    var pgfAngle, pgfWeight, prop, textAngle, textWeight;
    
    // Get the paragraph and text range angles.
    pgfAngle = pgf.FontAngle;
    prop = doc.GetTextPropVal (textRange.beg, Constants.FP_FontAngle);
    textAngle = prop.propVal.ival;
    
    // Get the paragraph and text range weights.
    pgfWeight = pgf.FontWeight;
    prop = doc.GetTextPropVal (textRange.beg, Constants.FP_FontWeight);
    textWeight = prop.propVal.ival;    
    
    if ((textAngle > pgfAngle) && (textWeight > pgfWeight)) {
        return ("BoldItalic");
    }
    else if (textAngle > pgfAngle) {
        return ("Italic");
    }
    else if (textWeight > pgfWeight) {
        return ("Bold");
    }
}
www.frameexpert.com
Inspiring
February 6, 2020

Thanks a lot!

For some reason

 

prop = doc.GetTextPropVal (textRange.beg, Constants.FP_FontAngle);

textAngle = prop.propVal.ival;

 

always returns 1, regardless of what the script finds. However I'm still doing Find (). Maybe I should ditch my approach in favor of your solution.

Michael

Jeff_Coatsworth
Community Expert
Community Expert
February 6, 2020

I think you need to zero in on the Constants.FV_FindCharacterFormatOverride bit & not italics in particular.

Inspiring
February 6, 2020

Yes, I'm able to get the overrides this way but then how do I tell what the override is.

I tried this:

var tl = new TextLoc (docStart, foundText.beg.offset);

var char_fmt = doc.GetTextPropVal (tl, Constants.FP_FontAngle).propVal.ival;

 

but it always returns 1, regardless of what it found - italic, regular, obliqued, etc. Where am I going wrong?

 

Michael

Correct answer
February 15, 2012

You're right, there are still a few bugs to work out of the documentation, though it has already improved dramatically since I started working w/ Extendscript last summer.

Either of the constants you found should be set as the ival for a FindObject PropVal, e.g.,:

     var myDoc = app.ActiveDoc;

     var docStart = myDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ;

     var tloc = new TextLoc(docStart,0);

     var findParams = AllocatePropVals(1);

     findParams[0].propIdent.num = Constants.FS_FindObject;

     findParams[0].propVal.valType = Constants.FT_Integer;

     findParams[0].propVal.ival = Constants.FV_FindCharacterFormatOverride;

     myDoc.Find(tloc,findParams);

Depending on what you're trying to accomplish, you may also want to take a look at the FormatOverride property of the Doc, Pgf, and Element objects.

Inspiring
February 6, 2020

I'm trying to search for a character style in FrameMaker - not a character tag. Someone made certain text italic without properly tagging it with a character tag. Now I need to assign a tag to the text with a specific formatting. I know I can do it without a script but I do need a script solution because I need to generate a list of paragraphs which have italic text in them. This list is needed for something else. Here is what I have so far but it doesn't find the formatted text:

var doc=app.ActiveDoc
var docStart = doc.MainFlowInDoc;

var tloc = new TextLoc (docStart, 0);

// setup find parameters
findParams = AllocatePropVals(1);

findParams[0].propIdent.num = Constants.FS_FindCharFmt;
findParams[0].propVal.valType = Constants.FP_FontAngle;
findParams[0].propVal.ival = 5; //5 is int for Italic

var foundText = doc.Find(tloc, findParams);
Can someone point me in the right direction.
Thank you
Michael