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

Override master page items on the 1st page only

Contributor ,
Mar 08, 2024 Mar 08, 2024

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

TOPICS
Scripting

Views

277

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 1 Correct answer

Community Expert , Mar 08, 2024 Mar 08, 2024

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]);
    }
}

Votes

Translate

Translate
Community Expert ,
Mar 08, 2024 Mar 08, 2024

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]);
    }
}

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 Expert ,
Mar 08, 2024 Mar 08, 2024

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

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
Guide ,
Mar 14, 2024 Mar 14, 2024

Copy link to clipboard

Copied

LATEST

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

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