Copy link to clipboard
Copied
Can someone tell me why my else if statement isn't working? I know I have 3 path items that have no fill and no stroke...
#target illustrator
var allDocs = app.documents;
var doc = app.activeDocument;
var allLayers = doc.layers;
var allLines = doc.pathItems;
var counter = 0;
for (var i = 0; i < allLines.length; i++) {
if (allLines.layer == "[Layer Tables]") {
if (allLines.stroked == true) {
counter++;
allLines.remove();
} else if (allLines.stroked == false && allLines.filled == false) {
counter++;
allLines.remove();
}
}
}
alert(counter + " items removed");
Adobe Illustrator CS4 Windows 64 Bit JavaScript
Hi subieguy2‌,
if I understand you right – you are on the wrong way.
I think you want to find and remove on the layer [Layer Tables] all path items which are stroked – or which have no outline AND no filling.
In this case you can try something like this:
...#target illustrator
//var allDocs = app.documents;
var aDoc = app.activeDocument;
var counter = 0;
try {
var specLayer = aDoc.layers.getByName ("[Layer Tables]");
var allSpecPI = specLayer.pathItems;
var PI_len = allSpecPI.length;
for (i = PI_
Copy link to clipboard
Copied
Hi subieguy2‌,
if I understand you right – you are on the wrong way.
I think you want to find and remove on the layer [Layer Tables] all path items which are stroked – or which have no outline AND no filling.
In this case you can try something like this:
#target illustrator
//var allDocs = app.documents;
var aDoc = app.activeDocument;
var counter = 0;
try {
var specLayer = aDoc.layers.getByName ("[Layer Tables]");
var allSpecPI = specLayer.pathItems;
var PI_len = allSpecPI.length;
for (i = PI_len - 1; i > 0; i--) {
if (allSpecPI.stroked == true) {
// only path items with filling and without stroke are remain
counter++;
allSpecPI.remove();
} else {
if (allSpecPI.stroked == false && allSpecPI.filled == false) {
counter++;
allSpecPI.remove();
}
}
}
alert(counter + " items removed");
}
catch (e) {
alert ("specific layer not found");
}
Have fun
Copy link to clipboard
Copied
your else if statement is ok, the problem is syntax in this line
if (allLines.layer == "[Layer Tables]") {
it should be
if (allLines.layer.name == "Tables") {
that will make your script work, but to make it work correctly follow pixxxel's script
Copy link to clipboard
Copied
That is exactly what I was trying to accomplish. Thank you both for your help and feedback!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now