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
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;
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
...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;
Copy link to clipboard
Copied
Excellent. Thank you!
Copy link to clipboard
Copied
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);
}
}