Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

deleting all matching items

Engaged ,
Oct 26, 2024 Oct 26, 2024

There are four rectangles in the document. All of them have no fill AND no stroke. When I try to delete them all based on this condition, I get that only two of them are deleted. I expected all of them to be deleted. What is the problem?

 

 

 

 

var doc = app.activeDocument;
processItems(doc.pageItems);

function hasNoFillAndStroke(item) {
    return !item.filled && !item.stroked;
}

function processItems(items) {
    for (var i = 0; i < items.length; i++) {
        var item = items[i];

        if (hasNoFillAndStroke(item)) {
            alert(item.typename);
            item.remove();
        }
    }
}

 

 

 

TOPICS
Scripting
228
Translate
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

correct answers 1 Correct answer

Community Expert , Oct 26, 2024 Oct 26, 2024

Hi @andyf65867865 ,

Use the loop in the reverse direction.

 

var doc = app.activeDocument;
processItems(doc.pageItems);

function hasNoFillAndStroke(item) {
    return !item.filled && !item.stroked;
}

function processItems(items) {
    for (var i = items.length - 1; i >= 0; i--) {
        var item = items[i];

        if (hasNoFillAndStroke(item)) {
            alert(item.typename);
            item.remove();
        }
    }
}

 

Translate
Adobe
Community Expert ,
Oct 26, 2024 Oct 26, 2024
LATEST

Hi @andyf65867865 ,

Use the loop in the reverse direction.

 

var doc = app.activeDocument;
processItems(doc.pageItems);

function hasNoFillAndStroke(item) {
    return !item.filled && !item.stroked;
}

function processItems(items) {
    for (var i = items.length - 1; i >= 0; i--) {
        var item = items[i];

        if (hasNoFillAndStroke(item)) {
            alert(item.typename);
            item.remove();
        }
    }
}

 

Best regards
Translate
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