• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

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

Engaged ,
Jul 21, 2022 Jul 21, 2022

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

TOPICS
Scripting

Views

146

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guide ,
Jul 21, 2022 Jul 21, 2022

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Would a valid exception be if you wanted to evaluate the selection before deleting?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines