Problem with overriding objects on custom size pages
Hi forum,
InDesign CC 2017.0 (12.0.0.81 x64 Build), Windows 10
I am trying to mimic the following manual steps by script:
The starting point: I have two master pages in the document – H-Horizontal and V-Vertical (both are of A3 page size). [None] is applied to the first and only page which has horizontal orientation (also A3).

Step 1: I apply V-Vertical master page to the first page and at this moment a warning pops-up: “Page 1 has a custom page size. This page can retain its current size or be resized to match the new master”. I choose “Use master page”.


Step 2 I Ctrl+Shift Click the four text frames to override the text frames and get the result I want

Now, let’s try to do the same by script:
Main();
function Main() {
var doc = app.activeDocument;
var page = doc.pages[0];
var orientation = "V";
var verMaster = doc.masterSpreads.itemByName("V-Vertical");
var horMaster = doc.masterSpreads.itemByName("H-Horizontal");
if (verMaster.isValid && horMaster.isValid) {
if (orientation == "V") {
page.appliedMaster = verMaster;
}
else if (orientation == "H") {
page.appliedMaster = horMaster;
}
var allMasterTextFtrames = page.appliedMaster.textFrames.everyItem().getElements();
for (var i = allMasterTextFtrames.length - 1; i >= 0; i--) {
if (allMasterTextFtrames.label != "") {
allMasterTextFtrames.override(page);
}
}
}
}

Note: the text frames have been moved, for some unconceivable reason, to bottom left. This happens at the moment when the script executes the override command: it happens even if I manually apply the master page and then override frames by script. I guess this is a bug.
Off the top of my head, I can work around this problem by recording x, y coordinates (or geometricBounds) of the frames with insertLabel first, and then, after applying override, read them using extractLabel and restore the original position.
Any ideas?
Here's the test file I used for testing.
— Kas
P.S. This happens only when the page size is different: if I use the horizontal master page -- var orientation = "H"; -- it works as expected. I haven't found the options available when I do this manually -- use master page size or keep current page size -- in the scripting DOM.


