Skip to main content
Inspiring
July 21, 2022
Question

Finding and removing from a document a PathItems whose area is less than 50.0

  • July 21, 2022
  • 1 reply
  • 428 views

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.... ???

This topic has been closed for replies.

1 reply

femkeblanco
Legend
July 21, 2022

Forward iteration problem. Iterate backwards. I.e.

for (k = LocLayer.pathItems.length - 1; k > -1; k--) {

For further details, see here 

rcraighead
Legend
July 21, 2022

Or select the matching items and delete after the loop is complete.

CarlosCanto
Community Expert
Community Expert
July 22, 2022

selecting objects is less efficient Ray, it's better not to select whenever possible.