Skip to content

Instantly share code, notes, and snippets.

@joshbduncan
Last active March 1, 2023 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbduncan/379d8ffe01b941ec81237df06c8da760 to your computer and use it in GitHub Desktop.
Save joshbduncan/379d8ffe01b941ec81237df06c8da760 to your computer and use it in GitHub Desktop.
Clean-up junky Ai files by reducing any selected group, compound path, and clipping mask contents to just paths.
/**
* Clean-up junky files by reducing any group, compound path, and clipping mask contents to just paths.
*
* This works no matter how nested the container object are and works for better for weird
* edge cases than trying to remove each element from each container via the API.
*/
var doc = app.activeDocument; // Get active document
var sel = doc.selection; // Get selected items
while (captureItemsToBeFixed().length > 0) {
app.executeMenuCommand("ungroup");
app.executeMenuCommand("releaseMask");
app.executeMenuCommand("noCompoundPath");
}
/** Get all selected groups, compound paths, and clipping masks. */
function captureItemsToBeFixed() {
var fixMe = [];
for (var i = 0; i < doc.selection.length; i++) {
item = doc.selection[i];
if (
doc.selection[i].typename === "GroupItem" ||
doc.selection[i].typename === "CompoundPathItem"
)
fixMe.push(doc.selection[i]);
}
return fixMe;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment