Skip to main content
M.Hasanin
Inspiring
April 18, 2021
Answered

Selecting the Odd Pages Only and Assign Label to it

  • April 18, 2021
  • 3 replies
  • 1815 views

Hi Experts, Please help me with the Code, i dont know what i missed!, it shouid select all Odd pages in the document and assign an Odd Label to it, but it doesnt work!.

 

 

(function () {
  var myDoc = app.activeDocument;
  var myPage = myDoc.pages;
  var myFrames = myDoc.textFrames;
    for (var i=0; i< myFrames.length ; i++) {
        if (myPage.side === PageSideOptions.LEFT_HAND) {
      myFrames[i].label ="odd";
    }
  }
}());

 

 

 Thanks in Advance

Best Regards

M.Hasanain

This topic has been closed for replies.
Correct answer Laubender

FWIW: Also discussed and solved in this thread:

 

Assign Script Label to Odd Pages Trying to Exclude Text Frames in Master page

https://community.adobe.com/t5/indesign/assign-script-label-to-odd-pages-trying-to-exclude-text-frames-in-master-page/m-p/11979418#M422765

 

Regards,
Uwe Laubender

( ACP )

3 replies

Community Expert
May 5, 2021

You could also assign a label to the page object itself.

This is even possible in the GUI with the Script Label panel, if pages are selected with the Page tool:

 

 

And if you ask for a specific value for textFrame.parentPage you could directly see if the text frame is left from the spine.

alert( app.selection[0].parentPage.label );

 

 

Note: parentPage will return null if the object is on the pasteboard.

 

Hm. The more I think about it…

If you test for side you only test for left or right from the spine. If a given page is an odd or even page is a bit fuzzy, it could be a matter of page naming and also important is the number of pages left or right from the spine. There could be up to 10 pages in one spread.

 

Regards,
Uwe Laubender

( ACP )

LaubenderCommunity ExpertCorrect answer
Community Expert
April 19, 2021

FWIW: Also discussed and solved in this thread:

 

Assign Script Label to Odd Pages Trying to Exclude Text Frames in Master page

https://community.adobe.com/t5/indesign/assign-script-label-to-odd-pages-trying-to-exclude-text-frames-in-master-page/m-p/11979418#M422765

 

Regards,
Uwe Laubender

( ACP )

Inspiring
April 18, 2021
Hi,
You have a couple of problems. First page.side will only work if you
have facing pages.
More importantly, in the loop you need to address the page, not the page item.
My question, why name the frames "odd" when a left hand page is even?
Below is how I wrote it (including a counter to return the number of
frames labeled):

var success = testSide ();
alert ("Total frames labeled: " + success);

function testSide () {
var myCounter = 0;
var myDoc = app.activeDocument;
var myPage = myDoc.pages;
var myFrames = myDoc.textFrames;
for (var i=0; i< myFrames.length ; i++) {
var myPage = myFrames[i].parentPage;
if (myPage.side == PageSideOptions.LEFT_HAND) {
myCounter ++;
myFrames[i].label ="odd";
}
}
return myCounter;
}
M.Hasanin
M.HasaninAuthor
Inspiring
April 18, 2021

Thank you alot, Actually the reason of naming the left page (odd) is that document is Right to left Document Becuase i use InDesign ME Support Arabic and Hebrew and Both Languages Writtened from Right to Left(RTL Document), I'm Beginner in Programming JavaScript, Actually I Need your advice about InDesign DOM, Because i have Difficulties with Understanding How to Catch Porperties and Values in sequence in the JavaScript Code, I need a Road Map Guide (Some Rules) in Connecting the Chain of the Codes, in the Example (MyFrames) will equal :

MyFrames = app.activeDocument.textFrames (i Understand that in InDesign DOM) its important to follow the Hierarchy of Commands, But a lot of times i got lost! and confused, can you tell me how to Overcome this problem to be a better coder with InDesign JavaScript and Thank you a lot, I learend a lot today.

Best Regards

M.Hasanain

Mohammad Hasanin