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

[JS] Override Alle Master Page Items

Community Beginner ,
May 26, 2009 May 26, 2009

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
8.0K
Translate
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

Translate
Advocate ,
May 26, 2009 May 26, 2009

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

Translate
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

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

Translate
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

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

Translate
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

Thanks a bunch, Harbs, that did the trick.

--

molsted

Translate
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

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?

Translate
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
Valorous Hero ,
May 14, 2014 May 14, 2014

#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){} 

    }

}

Translate
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

Are you overriding an already overridden object?

Harbs

Translate
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

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

Translate
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

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();

 

Translate
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
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
Translate
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