0

I can't get a Master page item override working. In the code what should I put as destinationPage? Currently, I keep getting an error message "Invalid object for this request"

var myDoc = app.activeDocument;
var myPages=myDoc.pages;

var myItems = myDoc.pages[0].appliedMaster.allPageItems;
    for (y=0; y<myItems.length; y++){
        if(myItems[y] instanceof TextBox){ //&& myItems[y] instanceof TextBox ){
                myItems[y].override(myPages[0]); //This bit doesn't work. What do I put here as destinationPage?
           }

        } 

Thanks

  • I can't find TextBox in my DOM reference. Try to change it to TextFrame. The code looks OK, try to run it through EST and see what error you are getting – Nicolai Kant Sep 18 '15 at 09:54

1 Answers1

0

I'm going to make a few assumptions here about what you are trying to achieve. I'm assuming that you are looking to override all of the TextFrames on the first page of your document.

var myDoc = app.activeDocument;
var myPages = myDoc.pages;

var myMasterPage = myPages[0].appliedMaster.pages[0]; // assuming single pages

var myItems = myPages[0].allPageItems; // assuming you want to override the items on the first page
for (y=0; y<myItems.length; y++) {
    var myItem = myItems[y];

    if (myItem.constructor === TextFrame) { // assuming you meant TextFrame instead of TextBox
        myItem.override(myMasterPage);
    }
}
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
  • On code *myPages.appliedMaster.pages[0];* we cannot use appliedMaster on pages object – Shiv Sep 06 '17 at 13:23
  • Should be `myPages[0].appliedMaster.pages[0]`. Edited the code above to reflect that, although it is still untested. – Josh Voigts Sep 06 '17 at 14:06