Site logo

Override all pageItems function

While overriding page items on a master spread who has more than one page, it’s important to check if the current item is located on the same side as the destination page. Otherwise you will end up with an error: invalid object for this request.

var doc = app.activeDocument;
overrideAllPageItems();

function overrideAllPageItems() {
	var page, allPageItems, pageItem;
	
	for (var c = 0; c < doc.pages.length; c++) {
		page = doc.pages[c];
		allPageItems = page.appliedMaster.allPageItems;
		
		for (var d = allPageItems.length - 1; d >= 0; d--) {
			pageItem = allPageItems[d];
			
			if (pageItem.parentPage.side == page.side) {
				pageItem.override(page);
			}
		}
	}
}

Alternatively, you can enclose override command with try-catch block to silently skip all problematic items.

try {
	pageItem.override(page);
} catch (err) {}