Last active
March 1, 2023 17:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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