Copy link to clipboard
Copied
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();
}
}
}
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();
}
}
}
Copy link to clipboard
Copied
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();
}
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now