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

Applying custom MasterPage using Extendscript

Community Beginner ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

Is it even possible?

The closest I've gotten to it is about 2 steps shy of actually applying the custom masterpage.

Fcodes([app.GetNamedCommand("MasterPageUsage").Fcode])

This gets the dialog box open but how do you choose the custom masterpage by name and apply it without opening a dialog box?

And on the flip side, if a custom masterpage is already set, how do you change it back to the default, "Right"?

Cheers

TOPICS
Scripting

Views

1.2K

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

Explorer , Aug 20, 2015 Aug 20, 2015

To my understanding, the Fcodes command is a way to simulate user input, therefore you get the dialog.

You can set the master page using this code:

// Optional: Get the current page of the active document

var doc, page;

doc = app.ActiveDoc;

page = doc.CurrentPage;

// Apply a master page called "Separator"

page.PageBackground = Constants.FV_BGD_OTHER;

page.MasterPage = "Separator";

To revert to the default master page, use

page.PageBackground = Constants.FV_BGD_DEFAULT;

Votes

Translate

Translate
Explorer , Feb 28, 2016 Feb 28, 2016

Actually, your instructions only set the background.  If the master page has a different layout (like the FIRST page might have more white space above the text frame), then you actually have to apply the master page formatting, like so...

var doc = app.ActiveDoc;

var first = doc.GetNamedMasterPage('First');

var right = doc.GetNamedMasterPage('Right');

var left = doc.GetNamedMasterPage('Left');

...

// If you have a page that needs "First", then you can say:

page.ApplyPageLayout(first);

//To reset all pag

...

Votes

Translate

Translate
Explorer ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

To my understanding, the Fcodes command is a way to simulate user input, therefore you get the dialog.

You can set the master page using this code:

// Optional: Get the current page of the active document

var doc, page;

doc = app.ActiveDoc;

page = doc.CurrentPage;

// Apply a master page called "Separator"

page.PageBackground = Constants.FV_BGD_OTHER;

page.MasterPage = "Separator";

To revert to the default master page, use

page.PageBackground = Constants.FV_BGD_DEFAULT;

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 Beginner ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

Excellent. Thank 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
Explorer ,
Feb 28, 2016 Feb 28, 2016

Copy link to clipboard

Copied

LATEST

Actually, your instructions only set the background.  If the master page has a different layout (like the FIRST page might have more white space above the text frame), then you actually have to apply the master page formatting, like so...

var doc = app.ActiveDoc;

var first = doc.GetNamedMasterPage('First');

var right = doc.GetNamedMasterPage('Right');

var left = doc.GetNamedMasterPage('Left');

...

// If you have a page that needs "First", then you can say:

page.ApplyPageLayout(first);

//To reset all pages to defaults, you would need to say:

page = doc.FirstBodyPageInDoc;

while(page.ObjectValid()) {

     if(page.PageIsRecto) {

          page.ApplyPageLayout(right);

     } else {

          page.ApplyPageLayout(left);

     }

}

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