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

Find something in a text selection

Community Expert ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

Dear Friends and experts,

Has anyone of you ever tried to find something programmatically in a text selection (aka text range)? The Find method works from a starting point (Text Location) towards the end of a document. When I select a part of the document and issue the search, it obviously starts just after the selection...

oTR = oDoc.TextSelection;
oFindParms = GetFindParameters (..);
oTR1 = oDoc.Find(oTR.beg, oFindParms); 

Even if the searched item is within the selection, the resulting oTR1 is behind the selction.

I have no idea how to do a search within the selection.

TOPICS
Scripting

Views

111

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 , Jun 30, 2022 Jun 30, 2022

Once you have the TextRange structure you can do

var doc, textRange, textList;
...
// See if there is one or more anchored frames in the text range.
textList = doc.GetTextForRange (textRange, Constants.FTI_FrameAnchor);

Votes

Translate

Translate
Community Expert ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

Have just found this post and hope it will solve my problem:

https://community.adobe.com/t5/framemaker-discussions/find-in-selection-with-extendscript/m-p/118660...

This is a solution to find text, but how to find an Anchored Frame or a variable within the selection?

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 ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

Once you have the TextRange structure you can do

var doc, textRange, textList;
...
// See if there is one or more anchored frames in the text range.
textList = doc.GetTextForRange (textRange, Constants.FTI_FrameAnchor);

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 ,
Jul 01, 2022 Jul 01, 2022

Copy link to clipboard

Copied

LATEST

Rick, excellent advice!

This works as expected - the found object is selected to indicate the find similar to the FM Find/Change dialogue.

KLD_Z.FindInSelection = function (sFType, sSearch) {
var oDoc = app.ActiveDoc, oTL, aTi, oTL, oTR = oDoc.TextSelection, oXX;

function ObjSelection (oXX) {
var oTL  = oXX.TextLoc;
var oTL2 = new TextLoc (oTL.obj, oTL.offset+1);
var oTR  = new TextRange (oTL, oTL2);
  return oTR;
}

  if (sFType == "ANCFRM") {
    aTi = oDoc.GetTextForRange (oTR, Constants.FTI_FrameAnchor);
    oXX = aTi[0].obj;
    return ObjSelection (oXX);
  } else if (sFType == "FOONOT") {
    aTi = oDoc.GetTextForRange(oTR, Constants.FTI_FnAnchor);   
    oXX = aTi[0].obj;
    return ObjSelection (oXX);
  } else if (sFType == "TBLANY") {
    aTi = oDoc.GetTextForRange(oTR, Constants.FTI_TblAnchor);   
    oXX = aTi[0].obj;
    return ObjSelection (oXX);  
 } 
} // --- end FindInSelection -----------------------------------------------

var oDoc, oTR;
  oDoc=app.ActiveDoc;
$.bp(true);
// select text containing an anchored frame (ANCFRM), table (TBLANY)..
  oTR = KLD_Z.FindInSelection ("TBLANY", "");
  oDoc.TextSelection = oTR;

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