Answered
Crop all open in Illustrator files
- December 30, 2021
- 1 reply
- 2193 views
Mark, it works perfectly 🙂
But I see it focus on an active document. How to make it running for all open documents in Illustrator ?
Glad it worked! Here's a version that applies to every open document.
var docs = app.documents;
for (var i = 0; i < docs.length; i++) {
removeAllButMap(docs[i], false);
}
alert('Processed ' + docs.length + ' files.')
function removeAllButMap(doc, showInfo) {
app.activeDocument = doc;
// select all and remove one level of clipping masks
executeMenuCommand('selectall');
executeMenuCommand('releaseMask');
doc.selection = null;
// loop over the path items, removing each
// one that doesn't match the criteria
var items = doc.activeLayer.pageItems,
keepCount = 0,
removeCount = 0;
for (var i = items.length - 1; i >= 0; i--) {
var item = items[i];
if (
item.typename == 'GroupItem'
&& item.clipped
&& item.pageItems.length > 1
&& item.pageItems[0].clipping == true
// this is the width and height of the map masks:
&& isNearEnough(item.pageItems[0].width, 1299.21, 2)
&& isNearEnough(item.pageItems[0].height, 1639.09, 2)
) {
keepCount++;
} else {
item.remove();
removeCount++;
}
}
app.redraw();
if (showInfo)
alert('Removed ' + removeCount + ' items, and kept ' + keepCount + ' items.');
}
// function that compares a value within tolerance:
function isNearEnough(n, m, tolerance) {
return Math.abs(n - m) < tolerance;
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.