Show page with object style applied javascript

Enthusiast ,
Jul 28, 2021 Jul 28, 2021

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

 

Best
M.Hasanain
TOPICS
Scripting

Views

99

Likes

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

Adobe Community Professional , Jul 28, 2021 Jul 28, 2021
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...

Likes

Translate

Translate
Adobe Community Professional , Jul 28, 2021 Jul 28, 2021
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...

Likes

Translate

Translate
Adobe Community Professional , Jul 28, 2021 Jul 28, 2021
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. 

Likes

Translate

Translate
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

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.

Likes

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
Enthusiast ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

@ajabon grinsmith Thanks a lot for your Help, this is Workerd!

Best
M.Hasanain

Likes

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

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

Likes

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

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. 

Likes

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
Enthusiast ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

LATEST

@ajabon grinsmith Thanks again, this is great, i already used this method with character and paragraph styles!

Best
M.Hasanain

Likes

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
Enthusiast ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

@Sunil Yadav Thanks a lot , this is great method

Best
M.Hasanain

Likes

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