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

[JS] Override Alle Master Page Items

Community Beginner ,
May 26, 2009 May 26, 2009

Copy link to clipboard

Copied

Hi all,

I'm trying to override all masterpage items from my script ...

function OverrideMasterItems(CurrentPage) {
     document.pages[CurrentPage].appliedMaster.pageItems.everyItem().override(document.pages[CurrentPage]);
}

but I get "Invalid object for this request".

Any hints?

--

molsted

TOPICS
Scripting

Views

7.4K

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

LEGEND , May 27, 2009 May 27, 2009

Like I said before: You're probably trying to override an object which is already overridden...

This should work. (Although there's probably more efficient ways to do this...)

function OverrideMasterItems() {
  var allItems = myDocument.pages[CurrentPage].appliedMaster.pageItems.everyItem().getElements();
  for(var i=0;i<allItems.length;i++){
    try{allItems.override(myDocument.pages[CurrentPage])}
    catch(e){}
  }
}

Harbs

Votes

Translate

Translate
Advocate ,
May 26, 2009 May 26, 2009

Copy link to clipboard

Copied

Presumably, CurrentPage is a number equal to the documentOffset of the page of interest.

But what is "document" -- you're not passing that into your function. Is it a global set to the activeDocument?

Once I defined that, your script worked for me (although I did have to delete a space in "pageItems".

Dave

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 Beginner ,
May 27, 2009 May 27, 2009

Copy link to clipboard

Copied

Hi Dave,

here's the script in its whole

#target indesign;

var myDocument = app.activeDocument;

var TotalPages = (myDocument.pages.count());

for(var CurrentPage=0; CurrentPage < TotalPages; CurrentPage++) {
     OverrideMasterItems();
}

function OverrideMasterItems() {
     myDocument.pages[CurrentPage].appliedMaster.pageItems.everyItem().override(myDocument.pages[CurrentPage]);

}

--

molsted

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
LEGEND ,
May 27, 2009 May 27, 2009

Copy link to clipboard

Copied

Like I said before: You're probably trying to override an object which is already overridden...

This should work. (Although there's probably more efficient ways to do this...)

function OverrideMasterItems() {
  var allItems = myDocument.pages[CurrentPage].appliedMaster.pageItems.everyItem().getElements();
  for(var i=0;i<allItems.length;i++){
    try{allItems.override(myDocument.pages[CurrentPage])}
    catch(e){}
  }
}

Harbs

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 Beginner ,
May 28, 2009 May 28, 2009

Copy link to clipboard

Copied

Thanks a bunch, Harbs, that did the trick.

--

molsted

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
Explorer ,
May 12, 2014 May 12, 2014

Copy link to clipboard

Copied

Hi Harbs, can this be apply to just one layer? lets say i only want to detach certain text frames on an specific layer, can that be done?

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
Guru ,
May 14, 2014 May 14, 2014

Copy link to clipboard

Copied

#target indesign; 

 

var myDocument = app.activeDocument; 

var TotalPages = (myDocument.pages.count()); 

 

for(var CurrentPage=0; CurrentPage < TotalPages; CurrentPage++) { 

     OverrideMasterItems(); 

function OverrideMasterItems() {

    var theLayer = myDocument.layers.item("Layer 1");

    var allItems = myDocument.pages[CurrentPage].appliedMaster.pageItems.everyItem().getElements(); 

    for(var i=0;i<allItems.length;i++){ 

        try{

            if (allItems.itemLayer == theLayer) {

                allItems.override(myDocument.pages[CurrentPage]);

            }

        }

        catch(e){} 

    }

}

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
LEGEND ,
May 26, 2009 May 26, 2009

Copy link to clipboard

Copied

Are you overriding an already overridden object?

Harbs

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
New Here ,
May 03, 2018 May 03, 2018

Copy link to clipboard

Copied

for(var i=myPage.appliedMaster.pageItems.length-1;i>=0; i--)

         {

                if(myPage.appliedMaster.pageItems.parentPage.side==myNewPage.side)

                        myPage.appliedMaster.pageItems.override(myPage); 

            }

Please try this. It worked for me.

Shivani

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
Enthusiast ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

For 2023 I noticed there was a Menu shortcut in pages, and that there was a way to execute these via script. Please note that "Parent" was formerly "Master" tested and this works as expected. I personally wasn't able to get the loops to work.

 

app.menuActions.itemByName("$ID/Override All Parent Page Items").invoke();

 

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
Enthusiast ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

LATEST

Hi @wckdtall , here the script to loop document to  override all parent pages items (tested in 2023) :

 

//Override All Document 
OverrideDoc();
function OverrideDoc() {
var mA = app.menuActions.itemByName("$ID/Override All Parent Page Items");
var doc = app.documents[0];
var allDocSpreads = doc.spreads.everyItem().getElements(); //Here is Pages Range
var allDocSpreadsLength = allDocSpreads.length;
for( var n=0; n<allDocSpreadsLength; n++ ) //Loop inSide Pages Range
{
	doc.layoutWindows[0].activeSpread = allDocSpreads[n]; //you can delete this, just to show process
	if( mA.isValid && mA.enabled ){ mA.invoke() };
};
    }

 

note that you can use any of these and will get the same results :

 

var mA = app.menuActions.itemByName("$ID/Override All Master Page Items");

 

or

 

var mA = app.menuActions.itemByName("$ID/Override All Parent Page Items");

 

 

Best
Mohammad Hasanin

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