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

Get Find count of the TextFrame

Participant ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

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
}

-Monisha
TOPICS
Scripting

Views

185

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 2 Correct answers

Community Expert , Oct 31, 2022 Oct 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

...

Votes

Translate

Translate
Participant , Oct 31, 2022 Oct 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);

Votes

Translate

Translate
Community Expert ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

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

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
Participant ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

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

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 ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

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

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 ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

LATEST

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??? 

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