Copy link to clipboard
Copied
Who can explain the incomprehensible behavior of the script. There are many PathItems in the scene. It is required to remove from the scene all PathItems whose area is less than 50.0.
-------------------------------------------------------------------------------
var aiDocument = app.activeDocument;
for (j = 0; j < aiDocument.layers.length; j++) {
var LocLayer = aiDocument.layers[j];
for (k = 0; k < LocLayer.pathItems.length; k++) {
if(LocLayer.pathItems[k].area <= 50.0){
LocLayer.pathItems[k].remove();
}
}
}
app.redraw();
-----------------------------------------------------------------------------------
After the script is executed, the part of the PathItems that meet this condition is removed, and the part remains in the document. And to completely remove such PathItems, you need to run this script several times.... ???
Copy link to clipboard
Copied
Forward iteration problem. Iterate backwards. I.e.
for (k = LocLayer.pathItems.length - 1; k > -1; k--) {
For further details, see here
Copy link to clipboard
Copied
Or select the matching items and delete after the loop is complete.
Copy link to clipboard
Copied
selecting objects is less efficient Ray, it's better not to select whenever possible.
Copy link to clipboard
Copied
Would a valid exception be if you wanted to evaluate the selection before deleting?
Copy link to clipboard
Copied
as in checking the area in this post? there's no need to select. I would either loop backwards as suggested or if I needed to do anything else with these objects before deleting, I would add them to an array. Then I could delete them looping forward as usual.
an exception would be when I need to use executeMenuCommands, those usually require a selection