Inspiring
February 14, 2023
Answered
Script to Remove extra Paths within a Compound Path?
- February 14, 2023
- 2 replies
- 4142 views
Hey Everyone,
I've been trying to write a script to remove the inside paths leaving the needed ones behind, but I can't get it quite right...
// Get the active document and selection
var doc = app.activeDocument;
var sel = doc.selection;
// Loop through the selection
for (var i = 0; i < sel.length; i++) {
var item = sel[i];
// Check if the item is a compound path
if (item.typename === 'CompoundPathItem') {
// Get the paths in the compound path
var paths = item.pathItems;
// Check the number of paths in the compound path
if (paths.length > 2) {
// If there are more than 2 paths, delete all but the outside and inside most paths
var numPaths = paths.length;
var firstPath = paths[0];
var lastPath = paths[numPaths - 1];
var secondPath = paths[1];
var secondLastPath = paths[numPaths - 2];
if (numPaths === 3) {
// If there are only 3 paths, delete the middle path
secondPath.remove();
} else {
// If there are more than 3 paths, delete all but the outside and inside most paths
for (var j = numPaths - 2; j > 1; j--) {
secondPath.remove();
lastPath.remove();
}
}
}
}
}