Copy link to clipboard
Copied
Hi Eveyone,
I tried to fetch the count of a particular text in a document according to pages but it does nothing, for that i used
var string = "hai how are you! hai hai";
var text = "hai";
for(var i=0; i<string.length; i++)
{
var myLines_first = app.activeDocument.stories.everyItem().lines.everyItem().words.everyItem(text).getElements();
for (var i = 0; i <= myLines_first.length-1; i++) {
myDoc = myLines_first[i].contents;
alert(myDoc);
}
anyone Please do guide on this.........
Look at your for loop using the result of findGrep().
Every item of that result contains a found text object. That found text object could be anywhere in your document. So you have to check:
1. Is it in overset?
2. Is it part of one or more text frames or text paths?
3. If in text frames or on text paths are the frames or the objects holding the text paths on a pasteboard or on a page?
4. If on a page, what page?
The result goes into an array. E.g. the page name or the position of the page i
...Copy link to clipboard
Copied
Hi,
You could use the FindText feature to find and count the occurence. See below
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "hai";
var list = app.activeDocument.findText ();
alert("No of Occurence " + list.length)
app.findTextPreferences = NothingEnum.nothing;
-Manan
Copy link to clipboard
Copied
Hi manan,
Thankyou so much. It's work great
Copy link to clipboard
Copied
Hi Manan,
If we need to fetch the search text count with page number individually means, how to do with this?? I have used the below code it dispalys the same count multiple times based on the pages in the document. How to dispaly the text count with page numbers individually.....
Please do guide me to complete this...
var myDocument = app.activeDocument;
var docRef = app.activeDocument;
var myPage = myDocument.pages.item(0);
alert(myPage);
var pageCount = docRef.pages.count();
for (var i = 0; i < 100; i++)
{
try
{
var frameRef = docRef.pages[i].textFrames.add();
with (frameRef)
{
app.findTextPreferences = NothingEnum.nothing;
var search = editText1.text;
app.findTextPreferences.findWhat ="Hai";
var list = app.activeDocument.findText ();
alert("No of Occurence : " + list.length)
app.findTextPreferences = NothingEnum.nothing;
}
}catch(e){}
}
-Jothi
Copy link to clipboard
Copied
I don't understand what your code does, you run a loop 100 times, and create a blank textframe each time then run the textfind query in context of the newly created textframe but call findText using the document object. It does not make sense to me at all. However if you want to find the page on which a word occurs, you could try the following code
wordObj.parentTextFrames[0].parentPage.name
Here wordObj would be objects in the list object in my code. So according to the code i shared before word = list[i] where i would be the loop counter you run over list object.
-Manan
Copy link to clipboard
Copied
Hi below given is the design of my code
var w = new Window('dialog');
var searchText = w.add('statictext', undefined, 'SearchText');
var editText = w.add('edittext', undefined, '');
editText.characters = 6;
var button = w.add('button', undefined, 'Find');
button.onClick = function()
{find();};
var listbox =w.add('listbox', undefined, '',
{numberOfColumns: 3, showHeaders: true,
columnTitles: ['Page:Nos', 'Search word Count']});
my function i have added is
function find()
{
var myDocument = app.activeDocument;
var myDocument = app.activeDocument;
var myPages = myDocument.pages.length;
alert(myPages);
app.findTextPreferences = NothingEnum.nothing;
var search = editText1.text;
app.findTextPreferences.findWhat =search;
var list = app.activeDocument.findText ();
alert("No of Occurence : " + list[myPages].length)
app.findTextPreferences = NothingEnum.nothing;
}
In this by giving search text then pressing add button i need to dispaly the page number in 1st column and the search text count according to pages in 2nd column but my code shows an error message that page is undefined
Please do guide on this to complete it.......................
Copy link to clipboard
Copied
Hi,
I tried to dispaly the count occurance with page no for that i have used the below code but it doesn't make sense on it......
Please do guide on this...........
var myDocument = app.activeDocument;
var myPages = myDocument.pages.length;
for(var i=0; i<myPages; i++)
{
app.findGrepPreferences = NothingEnum.NOTHING;
var search = editText1.text;
app.findGrepPreferences.findWhat = search ;
//app.findChangeTextOptions.caseSensitive = true;
var list = app.activeDocument.findGrep ();
alert("No of Occurence in page " +i +" is "+ list[i].length);
app.findGrepPreferences = NothingEnum.NOTHING;
}
Copy link to clipboard
Copied
Hi Jothi,
as far as I can see your findText() or findGrep() is with scope document.
So you have to sort the result array. Every instance of found text could be in one or more text containers. Or even in overset text. Every identified text container could be on a page with a specific documentOffset or on a pasteboard. Also on one of the master spreads. So you have to check also for this.
A different algorithm could work like that:
Loop all document pages.
At the start of the loop lock all items in the document.
Unlock all items on the page your loop is currently visiting.
Do your document.findGrep() or document.findText() on unlocked items only.
You can be sure that all found text is on that specific page.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi,
I have modified the code but doesn't get my expected output what's the problem in my code. Code i have modified is
var myDocument = app.activeDocument;
var myPages = myDocument.pages.length;
app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "hai";
var list = app.activeDocument.findGrep ();
for(var i =0; i<= list.length; i++)
{
alert("No of Occurence in page "+myPages +" is "+ list[myPages].length);
app.findGrepPreferences = NothingEnum.NOTHING;
}
Copy link to clipboard
Copied
Hi Jothi,
I don't see that you are doing something reasonable with your found text.
At least see into the list[i].parentTextFrames array. Loop that array and check for parentPage of every found item in that array. If value of parentPage is null the text frame of the found piece of text is on the pasteboard outside of a page. If a page is returned you could fetch its name or the documentOffset.
Feed an array with the result, sort it after documentOffset ( that's an integer and no string ) or sort it in a way you like…
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Sorry I Can't understand clearly a little bit confused!!!!! with this. Can you edit my code
Copy link to clipboard
Copied
Look at your for loop using the result of findGrep().
Every item of that result contains a found text object. That found text object could be anywhere in your document. So you have to check:
1. Is it in overset?
2. Is it part of one or more text frames or text paths?
3. If in text frames or on text paths are the frames or the objects holding the text paths on a pasteboard or on a page?
4. If on a page, what page?
The result goes into an array. E.g. the page name or the position of the page in the document.
Then you can sort the array and check if some pages are missing.
All properties and methods for this are on the table.
From a found text you can get the parentTextFrames array that could contain one or more items.
The items could be:
undefined ( means: the text is in overset )
textFrame
textPath
If an item is textFrame look into property parentPage of that textFrame.
If an item is textPath look into property parentPage of textPath.parent.
The value of parentPage could be:
null ( means: text frame is on the pasteboard )
page
If page look into property name of the page.
Or look into property documentOffset of the page.
Store that value into an array and sort the array. Then you have a list of page names or numbers that reflect the position of a page in the document where your found text actually was found.
Regards,
Uwe Laubender
( ACP )
EDIT: Added the example with textPath
Copy link to clipboard
Copied
Thankyou so much. It work correctly i'll mark your answer as correct.
-Jothi