Photoshop CC 2017. Using this loop to delete paths one by one results in some paths (out of 8) being deleted only:
for(i = 0; i < app.activeDocument.pathItems.length; i++) {
alert(i)
app.activeDocument.pathItems[i].remove();
}
The length gets reported as being 8. However alert(i) only shows 4 times. All the paths get removed only if running the loop multiple times. I'm deleting them one by one because I want to keep a path with a certain name. Any ideas?
You are changing pathItems as you loop through it. When you delete item i there will be a new item at position i that you skip.
If you do the loop backwards it won't cause any problems
for(i = app.activeDocument.pathItems.length -1; i >= 0; i--) {
alert(i)
app.activeDocument.pathItems[i].remove();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With