Search code examples
javascriptadobe-indesign

InDesign - remove master items override use selectors


I want to remove the overrides from master items, but just items in object style X, i wrote:

var doc = app.activeDocument;
var pgs = doc.pages;
for(i = 0; i<pgs.length; i++){
    pgs[i].removeOverride(doc.objectStyles.itemByName("myObject"))
}

And all overrides removed. how i do it? Thank in advance


Solution

  • This is admittedly not very well documented in the InDesign Object Model, but using removeOverride() on a page (as you are doing) simply removes all overrides from all pageItems on that page. Also, removeOverride() does not take any arguments. Instead you could use it like this:

    var pi = app.activeDocument.pageItems;
    var myOS = app.activeDocument.objectStyles.item('myObject');
    for(var i = 0; i < pageItems.length; i += 1) {
      if(pi[i].appliedObjectStyle === myOS) page[i].removeOverride();
    }
    

    This loops through all pageItems, checks each if it has the objectStyle and if so removes the override.