Skip to main content
Inspiring
October 31, 2022
Answered

Get Find count of the TextFrame

  • October 31, 2022
  • 2 replies
  • 450 views

Hi,

For each text frame, I used to get the page number. Presently, InDesign documents with 6 text frames will display page numbers for just four of the text frames, not all of the text frames. Here is the script I used to do it. 

 

var MSIDvalue = [];
var myXMLFile;
var getsearchtextpageNUmber = [];
var getxmlvalues =[];
var getCDATAValue = [];
var InddFrameValue = [];
var getPageNumberValue = [];
var getsearchtextpageNUmber ;
var getsearchtextpageNUmber =[];
var myGroup = app.activeDocument;
var allPageItemsOfGroup = myGroup.allPageItems;
for(var n=0;n<allPageItemsOfGroup.length;n++){
var myObject = allPageItemsOfGroup[n].getElements()[0];
if(myObject.constructor.name === "TextFrame" )
var myFrame = app.activeDocument.textFrames;
var mySelectedXMLItem = myFrame[n].associatedXMLElement;
if(mySelectedXMLItem != null && mySelectedXMLItem.markupTag.name != null)
var node_TBGUID = myFrame[n].associatedXMLElement.xmlAttributes.itemByName("MSID").value;
MSIDvalue.push(node_TBGUID);
var myFrames = myFrame[n].texts[0].contents;
app.findGrepPreferences=NothingEnum.NOTHING; //to reset the Grep search
app.findGrepPreferences.findWhat = myFrames; //the word(s) you are searching
var find = app.activeDocument.findGrep (true); //execute search
var a = app.activeDocument.findGrep( true )
for (var r = 0; r < a.length; r++)
getsearchtextpageNUmber.push(a [r].parentTextFrames[0].parentPage.name) ; //output
}

This topic has been closed for replies.
Correct answer MonishaRajendran

Hi @Manan Joshi 

 

I have modified the script and now it's working fine. Hereby I have attached the script which I have used.

 

var doc = app.activeDocument;
var gettextframe = app.activeDocument.textFrames;
for(var q=0;q<gettextframe.length;q++)
getPageNumberValue.push(doc.textFrames[q].parentPage.name);

2 replies

Robert at ID-Tasker
Legend
October 31, 2022

Are you sure your code is working correctly??? It looks a bit strange... You are trying to process all TextFrames in the group - but then you are referencing to ALL TextFrames in the document??? 

Community Expert
October 31, 2022

You need to debug and see that the array "a" has 6 elements or not. This array is populated with the findGrep result so check if the result should bring in all the frames as you expect. Also, see the following two consecutive statements, doing the same thing then why do you need both

var find = app.activeDocument.findGrep(true); //execute search
var a = app.activeDocument.findGrep(true)

In addition as I mentioned in another thread, you need to check for the possibility of the pageitem not being on a page at all.

-Manan

MonishaRajendranAuthorCorrect answer
Inspiring
October 31, 2022

Hi @Manan Joshi 

 

I have modified the script and now it's working fine. Hereby I have attached the script which I have used.

 

var doc = app.activeDocument;
var gettextframe = app.activeDocument.textFrames;
for(var q=0;q<gettextframe.length;q++)
getPageNumberValue.push(doc.textFrames[q].parentPage.name);

-Monisha
Robert at ID-Tasker
Legend
October 31, 2022

The name of your variable is a bit "misleading" - .parentPage.name returns "name" of the page - not its index in the document.