Highlighted

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

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

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

 

TOPICS
Scripting

Views

50

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

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

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

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

 

TOPICS
Scripting

Views

51

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
Nov 14, 2020 0
Participant ,
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]);}

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
Reply
Loading...
Nov 15, 2020 0
Adobe Community Professional ,
Nov 15, 2020

Copy link to clipboard

Copied

And does that work for you?

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
Nov 15, 2020

Copy link to clipboard

Copied

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

 

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
Reply
Loading...
Nov 15, 2020 0