Copy link to clipboard
Copied
Hi Experts, I made Script that loop through pages and show the Page Contain Specific Applied Object Styles, Here is my Script, I just need to know if this method is correct, it doesnt give me any error, i just want to be sure its accurate! , i used the following :
app.windows[0].activePage = app.documents[0].pages.item(i);
here is the Code Snippest :
function ObjStyleGREP() {
var myDoc = app.activeDocument
var myObjectStyle = myDropdown3.selection.index
//StartChange-Object Styles
clean_up (app.activeDocument, true);
//-------------------------------------------------//
myFoundText = myDoc.findGrep();
for(i=0;i<myFoundText.length;i++){
//Added to Change Text
if (ShowResults.value == true) { //Show and Apply
$.sleep(250); //Wait 25ms
app.windows[0].activePage = app.documents[0].pages.item(i); //only for Object Styles
myFoundText[i].parentTextFrames[0].appliedObjectStyle=myDoc.allObjectStyles[myObjectStyle];
}else{ //only Apply Find
myFoundText[i].parentTextFrames[0].appliedObjectStyle=myDoc.allObjectStyles[myObjectStyle];
}
}
}
Thanks in Advance
Mohammad Hasanin
3 Correct answers
I looked at your code (but I haven't tried it as it seems to be part of the whole).
There is one thing that is obviously strange.
The variable "i" is used in the search result loop. But it is also used for certain page indexes.
You need to change the "i" used in the function to another variable name, for example "j".
Alternatively, specify the active page to,
app.windows[0].activePage = myFoundText[i].parentTextFrames[0].parentPage;
Then it will probably be fixed.
The "parentPage" property can only be
...It looks to me if OP wants to select those pages which has already applied particular object style, then it can be easily done like this :
findObjectStyle("Test Object Style Name");
function findObjectStyle(objectStyleName){
var myDoc = app.documents[0];
app.findObjectPreferences.appliedObjectStyles = objectStyleName;
var allFound = myDoc.findObject();
for(var i = 0; i < allFound.length; i++){
app.windows[0].activePage = allFound[i].parentPage;
allFound[i].s
...
hi, I have another idea,
for(var i = 0; i < myFoundText.length; i++){
myFoundText[i].showText();
$.sleep(250);
}
This will inevitably change the active page as well.
thanks.
Copy link to clipboard
Copied
I looked at your code (but I haven't tried it as it seems to be part of the whole).
There is one thing that is obviously strange.
The variable "i" is used in the search result loop. But it is also used for certain page indexes.
You need to change the "i" used in the function to another variable name, for example "j".
Alternatively, specify the active page to,
app.windows[0].activePage = myFoundText[i].parentTextFrames[0].parentPage;
Then it will probably be fixed.
The "parentPage" property can only be used with InDesign CS5 or later.
Regards.
Copy link to clipboard
Copied
@ajabon grinsmith Thanks a lot for your Help, this is Workerd!
Mohammad Hasanin
Copy link to clipboard
Copied
It looks to me if OP wants to select those pages which has already applied particular object style, then it can be easily done like this :
findObjectStyle("Test Object Style Name");
function findObjectStyle(objectStyleName){
var myDoc = app.documents[0];
app.findObjectPreferences.appliedObjectStyles = objectStyleName;
var allFound = myDoc.findObject();
for(var i = 0; i < allFound.length; i++){
app.windows[0].activePage = allFound[i].parentPage;
allFound[i].select();
$.sleep(2000);
}
}
And as far as original code is concern, in that OP is trying to find something with grep or regexp & hardcoded activating Page using variable "i" independent of either there is any object with specific object style is available or not.
And forcefully applying that object style to first text frame of every next page.
Which seems to me is inaccurate.
Best
Sunil
Copy link to clipboard
Copied
hi, I have another idea,
for(var i = 0; i < myFoundText.length; i++){
myFoundText[i].showText();
$.sleep(250);
}
This will inevitably change the active page as well.
thanks.
Copy link to clipboard
Copied
@ajabon grinsmith Thanks again, this is great, i already used this method with character and paragraph styles!
Mohammad Hasanin
Copy link to clipboard
Copied
@Sunil Yadav Thanks a lot , this is great method
Mohammad Hasanin

