Highlighted

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

Participant ,
Feb 15, 2012

Copy link to clipboard

Copied

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?

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.

TOPICS
Scripting

Views

909

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

Participant ,
Feb 15, 2012

Copy link to clipboard

Copied

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?

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.

TOPICS
Scripting

Views

910

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 15, 2012 0
Participant ,
Feb 15, 2012

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2012 0
Explorer ,
Feb 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Explorer ,
Feb 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

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.");
    }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

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");
    }
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Explorer ,
Feb 06, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

I am using textRange.beg in my code. What are you returning from Find? If you are using a different variable, you have to use that in GetTextPropVal. For example, foundText.beg.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Explorer ,
Feb 06, 2020

Copy link to clipboard

Copied

Yes, I'm doing

 

var fountText = doc.Find(tloc, findParams);

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

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

 

and that always returns 1. I used your approach meanwhile and it works great, I just wish GetText() would support TextRange. As it is, I have to GetText() the whole paragraph and then substring() the contents from it using beginning and end of the text range. That could be inaccurate because of markers and special characters. Hopefully I won't run into that.

I believe I can complete the rest of the code now. Thanks a lot again.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Adobe Community Professional ,
Feb 06, 2020

Copy link to clipboard

Copied

Making a TextLoc shouldn't be necessary. You should be able to use doc.GetTextPropVal (fountText.beg...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Explorer ,
Feb 06, 2020

Copy link to clipboard

Copied

Yep, you are spot-on. This works and returns 5 - italic. Thank  you.

I mentioned that I'm trying to get a text content of TextRange. Do you know of a direct way to do that - getting substring() from pgf.GetText() is not that great when there are markers in the text - they throw off positions by 1 for each marker so the resulting string is cut off at the beginning by the same amount of characters as there are markers.

Earlier, in FrameScript there was a way to count the markers in the paragraph prior to TextRange and minus that from substring. Now... where do I begin.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2020 0
Explorer ,
Feb 07, 2020

Copy link to clipboard

Copied

Nevermind, I figured it out.

 

textRange = new TextRange (new TextLoc (pgf,beg_offset), new TextLoc (pgf,end_offset));

var text = doc.GetTextForRange (textRange, Contants.FTI_String);

var range_content = '';

for (var a = 0 ; a < text.length; a++) {

    range_content += text [a].sdata;

}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 07, 2020 0