0
Contributor
,
/t5/indesign-discussions/assign-page-odd-even-range-to-masterpage-by-script/td-p/11596167
Nov 14, 2020
Nov 14, 2020
Copy link to clipboard
Copied
Hi,
I have:
2 Masterpages (A-Master + B-Master).
Sequential document -pages-, with odd and even pages. (no "facing" pages).
I want assign odd pages to A-Master and even pages to B-Master.
By "manual" I can type in MasterPage dialogbox: i.e. "1,3,5,7,9" or "2,4,6,8,10".
I would actually like: A-Master: odd and B-Master: even
How do that with script.
myDoc.pages.itemByRange(myStartPage, myEndPage).appliedMaster = myDoc.masterSpreads.item("B-Master");
but... that's a range: from-to ... not a list
Regards,
Jan
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Contributor
,
Nov 15, 2020
Nov 15, 2020
Above is just part of the script.
Yes, it works for me, see the whole script below.
Regards,
Jan
//Apply A-MasterPage to odd-pages + B-MasterPage to even pages
//A document with pages must exist.
//A second MasterPages must exist.
//====================================================
if (app.documents.length > 0) main();
function main()
{
var mydoc = app.activeDocument;
//get MasterPages
var everyMaster = mydoc.masterSpreads.everyItem().name;
var masters = ["[None]"];
f
...
jan99x
AUTHOR
Contributor
,
/t5/indesign-discussions/assign-page-odd-even-range-to-masterpage-by-script/m-p/11596199#M403751
Nov 15, 2020
Nov 15, 2020
Copy link to clipboard
Copied
I found:
// Apply master to the page. i = counter pages
if (i % 2 == 0)
{pages[i].appliedMaster = doc.masterSpreads.itemByName(masters[1]);}
else
{pages[i].appliedMaster = doc.masterSpreads.itemByName(masters[2]);}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/assign-page-odd-even-range-to-masterpage-by-script/m-p/11596396#M403755
Nov 15, 2020
Nov 15, 2020
Copy link to clipboard
Copied
And does that work for you?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
LATEST
/t5/indesign-discussions/assign-page-odd-even-range-to-masterpage-by-script/m-p/11596680#M403768
Nov 15, 2020
Nov 15, 2020
Copy link to clipboard
Copied
Above is just part of the script.
Yes, it works for me, see the whole script below.
Regards,
Jan
//Apply A-MasterPage to odd-pages + B-MasterPage to even pages
//A document with pages must exist.
//A second MasterPages must exist.
//====================================================
if (app.documents.length > 0) main();
function main()
{
var mydoc = app.activeDocument;
//get MasterPages
var everyMaster = mydoc.masterSpreads.everyItem().name;
var masters = ["[None]"];
for (var i = 0; i < everyMaster.length; i++)
{
masters.push(everyMaster[i]);
}
//dialogbox
var maxPages = mydoc.pages.count();
var len = masters.length;
if (confirm("Found Pages: " + maxPages + "\n\n\nFound MasterPages:\n" + masters[1] + "\n" + masters[2] + "\n\n\n\n\nContinue?"))
{
var pages = mydoc.pages;
for (var i = 0; i < pages.length; i++)
{
// Apply master to the page.
if (i % 2 == 0)//remainder
{
pages[i].appliedMaster = mydoc.masterSpreads.itemByName(masters[1]);// odd pages
}
else
{
pages[i].appliedMaster = mydoc.masterSpreads.itemByName(masters[2]);//even pages
}
}
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

