• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ExtendScript: search for any character tag

Community Expert ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Dear experts,

I try to find any character format with the following script:

var aLocNames = [], j, jMax, oFindParms, oPgf, sTag, tRange, tRange, zz;
//
  tRange = new TextRange();
  oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
  tRange.beg.obj = tRange.end.obj = oPgf;   // set up the starting TR
  tRange.beg.offset = tRange.end.offset = 0; 
// Find any character format   iFS, iFV, sSearch, iMode, bWord, bCase, bBack (wildcard)
  oFindParms = KLD_F.GetFindParameters (5, 0, "*", 1, false, false, false);
  KLD_Z.InitFA_errno ();                  // reset - it is write protected
  tRange = oDoc.Find (tRange.beg, oFindParms);// initial find
  zz = FA_errno;
  oDoc.TextSelection = tRange;               // debug: indicate visually
  oDoc.ScrollToText(tRange);
$.bp(true);
  sTag   = tRange.beg.obj;     //<<<<<<< How to find the tag name?
  aLocNames.push(sTag);

  while(FA_errno === Constants.FE_Success) {
    tRange = oDoc.Find (tRange.beg, oFindParms);
    zz = FA_errno;                 // debug: 0 OK; -95 not found
    oDoc.TextSelection = tRange;   // debug: indicate visually
    oDoc.ScrollToText(tRange);
$.bp(true);
    sTag   = tRange.beg.obj;   //<<<<<<< How to find the tag name?
    aLocNames.push(sTag);
    tRange.beg.offset += 1;        // to continue search
  }

Text range is found and highlighted, if script is stopped.

However, tRange.beg.obj is a paragraph object, which does not have a property for the character format.

IMHO I need to do this:

Get the paragraph and search it's parts with textObj.GetText(Constants.FTI_CharPropsChange);

But how t  handle the flag Constants.FTF_CHARTAG ?

Views

213

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 17, 2021 Aug 17, 2021

This may be useful to you Klaus:

#target framemaker

var doc, pgf, fmtsInUse;

fmtsInUse = [];

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

getPgfCharFmts (pgf, doc, fmtsInUse);

alert (fmtsInUse);

function getPgfCharFmts (pgf, doc, fmtsInUse) {  
  
    var end = Constants.FV_OBJ_END_OFFSET, begin = 0, textRange = 0, prop, charTag;  
      
    var textList = pgf.GetText(Constants.FTI_CharPropsChange);  
    for (var i = textList.length - 1; i >= 0; i -= 1) {  
       if (Constants.
...

Votes

Translate

Translate
Community Expert ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

This may be useful to you Klaus:

#target framemaker

var doc, pgf, fmtsInUse;

fmtsInUse = [];

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

getPgfCharFmts (pgf, doc, fmtsInUse);

alert (fmtsInUse);

function getPgfCharFmts (pgf, doc, fmtsInUse) {  
  
    var end = Constants.FV_OBJ_END_OFFSET, begin = 0, textRange = 0, prop, charTag;  
      
    var textList = pgf.GetText(Constants.FTI_CharPropsChange);  
    for (var i = textList.length - 1; i >= 0; i -= 1) {  
       if (Constants.FTF_CHARTAG & textList[i].idata) {  
           begin = textList[i].offset;  
            if (begin !== end) {  
                textRange = new TextRange (new TextLoc (pgf, begin), new TextLoc (pgf, end));  
                prop = doc.GetTextPropVal (textRange.beg, Constants.FP_CharTag);  
                if ((prop.propIdent.num) && (prop.propVal.sval !== "")) {  
                    // Get the character format that is applied to the text range.
                    charTag = prop.propVal.sval;
                    if (fmtsInUse.indexOf (charTag) === -1) {
                        fmtsInUse.push (charTag);
                    }
                }  
            }  
            end = begin;  
        }  
    }  
}

Votes

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
community guidelines
Community Expert ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

LATEST

Thank You very much, Rick!

I just had to put a loop around to get a complete list of the used character tags - and then applied a sort which removed duplicates:

 

  oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
  while (oPgf.ObjectValid()) {
    getPgfCharFmts (oPgf, oDoc, aLocNames);
    oPgf = oPgf.NextPgfInDoc
  }

 

The catalogue may report more character formats as used than this function does. IMHO the catalogue is wrong, because the additionally flagged formats can not be found with the Find/Change dialogue…

Votes

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
community guidelines