Skip to main content
K.Daube
Community Expert
Community Expert
June 30, 2022
Answered

Find something in a text selection

  • June 30, 2022
  • 1 reply
  • 304 views

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.

This topic has been closed for replies.
Correct answer frameexpert

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

1 reply

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
June 30, 2022

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/11866008#M69682

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

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
June 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);
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
July 1, 2022

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;