Copy link to clipboard
Copied
Hey guys,
I have found this script on the internet (link) and it's exacty what I need, however I'm getting this error when I try to run it "null is not an object". Can anyone take a look?
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myMasterPage = myPages[0].appliedMaster.pages[0];
var myItems = myPages[0].allPageItems;
for (y=0; y<myItems.length; y++) {
var myItem = myItems[y];
if (myItem.constructor === TextFrame) {
myItem.override(myMasterPage);
}
}
Thanks,
Rogerio
You don't override a live page's items. You override the master page items to the target page (passed in the override function). As in:
var myDoc = app.activeDocument;
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myMasterPage = myPages[0].appliedMaster.pages[0];
var myItems = myMasterPage.allPageItems;
for (y=0; y<myItems.length; y++) {
var myItem = myItems[y];
if (myItem.constructor === TextFrame) {
myItem.override(myPages[0]);
}
}
Copy link to clipboard
Copied
You don't override a live page's items. You override the master page items to the target page (passed in the override function). As in:
var myDoc = app.activeDocument;
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myMasterPage = myPages[0].appliedMaster.pages[0];
var myItems = myMasterPage.allPageItems;
for (y=0; y<myItems.length; y++) {
var myItem = myItems[y];
if (myItem.constructor === TextFrame) {
myItem.override(myPages[0]);
}
}
Copy link to clipboard
Copied
Remember to put the myItem.override() inside a try/catch block. This is because it will throw an error if the item has already been overridden.
- Mark
Copy link to clipboard
Copied
Also take note that myItem.override(targetPage) tends to shift the item when new pages have been added or for other obscure reasons.
A generic bugfix is based on the targetPage.masterPageTransform matrix, whose nonzero translation components typically reflect the undesired shift:
// Fixed override()
var mx = targetPage.masterPageTransform.matrixValues.slice(-2);
mx[0] += 'pt';
mx[1] += 'pt';
try{ myItem.override(targetPage).move(void 0, mx) }
catch(_){ }
Best,
Marc