-
1. Re: Detach all master page elements (entire document)?
MarkWalsh Mar 27, 2012 12:31 PM (in response to bpylant)See if this does what you need:
#target indesign
var count = app.documents.count();
// Make sure there is an active document first
if (count > 0) {
processDocument(app.activeDocument);
} else {
alert ("You don't have any documents open.");
}
function processDocument(docRef) {
if (docRef == null || docRef == '') {
return false;
}
var masterCount = docRef.masterSpreads.length;
if (masterCount > 0) {
for( var i = 0; i < masterCount; i++) {
var m = docRef.masterSpreads[i];
var pageCount = m.pages.length;
if (pageCount > 0) {
for( var j = 0; j < pageCount; j++) {
var p = m.pages[j];
OverrideMasterItems(p);
}
}
}
}
var pageCount = docRef.pages.length;
if (pageCount > 0) {
for( var i = 0; i < pageCount; i++) {
var p = docRef.pages[i];
OverrideMasterItems(p);
}
}
}
function OverrideMasterItems(p) {
if (p == null || p == '') {
return false;
}
if (p.appliedMaster == null || p.appliedMaster == '') {
return false;
}
// Override all items on Page
var allItems = p.appliedMaster.pageItems.everyItem().getElements();
for(var i=0;i<allItems.length;i++){
var pi = allItems[i];
if (!pi.overridden) {
try{
allItems[i].override(p);
}
catch(e){}
}
}
// Remove master from page
p.appliedMaster = NothingEnum.nothing;
} // END OverrideMasterItems
-
2. Re: Detach all master page elements (entire document)?
absqua Mar 27, 2012 12:48 PM (in response to MarkWalsh)PageItem has a detach() method:
function main() { var doc = app.activeDocument, i, l, page, j, k; for (i = 0, l = doc.pages.length; i < l; i++) { page = doc.pages[i]; if (page.appliedMaster !== null) { for (j = 0, k = page.appliedMaster.pageItems.length; j < k; j++) { try { page.appliedMaster.pageItems[j].override(page); } catch(e) {} } } page.pageItems.everyItem().detach(); } } if (app.documents.length > 0) { app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Detach Master Page Items"); }Jeff
-
3. Re: Detach all master page elements (entire document)?
bpylant Mar 28, 2012 7:31 AM (in response to absqua)Awesome, thanks so much!
I wish I knew more about this stuff... every time I start to teach myself to code I get overwhelmed so quickly. I should really take some classes, I guess.
-
4. Re: Detach all master page elements (entire document)?
absqua Mar 28, 2012 7:58 AM (in response to bpylant)bpylant wrote:
I wish I knew more about this stuff... every time I start to teach myself to code I get overwhelmed so quickly. I should really take some classes, I guess.
If your primary interest is in scripting InDesign, I would recommend you start with Peter Kahrel's book, which will help you begin doing actual work without getting bogged down (and overwhelmed!) in abstractions—that stuff can wait for later.
-
5. Re: Detach all master page elements (entire document)?
bpylant Mar 28, 2012 10:35 AM (in response to absqua)Great, thanks for the recommendation! I didn't even know such a book existed...!
-
6. Re: Detach all master page elements (entire document)?
schiuma24 May 12, 2014 8:07 AM (in response to absqua)hey, this script is great, but, can it be applied to just Items on an specific layer???


