• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

assign page (odd + even) range to MasterPage (by script)

Participant ,
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.


I saw: https://community.adobe.com/t5/indesign/cs3-vb-why-doesn-t-applying-masterpage-on-page-range/m-p/191...

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

Views

755

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 1 Correct answer

Participant , Nov 15, 2020 Nov 15, 2020

@Peter Kahrel 

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
...

Votes

Translate

Translate
Participant ,
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]);}

Votes

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

And does that work for you?

Votes

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
Participant ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

LATEST

@Peter Kahrel 

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
            }
        }
    }
}

 

Votes

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