Copy link to clipboard
Copied
Why aren't all the paths that may have a fill on them, within the layer by name "Hairs_TopNose" not being iterated though and having, if exists their fill removed ?
var curDoc = app.activeDocument;
var lyr = curDoc.layers.getByName("Hairs_TopNose");
var pathss = lyr.hasSelectedArtwork;
var pth = lyr.pathItems.length;
var patth = lyr.pathItem;
if (pathss==1) {
for(pth=0;pth<patth.filled=false;i++)
}else{
alert("Fill on Paths Removed");
};
and in the if statement you have the wrong var as well.
while (i--) {
if (patth.filled) {
patth.filled=false;
use pth not patth.
pth is the array of path items
patth is the number of items in the array.
Copy link to clipboard
Copied
Your for-loop, looks like it is missing.
Copy link to clipboard
Copied
When you said missing; I realized I missed a curly brace, until adding it I got an error I didn't previous have, illegal use of the word else.
Copy link to clipboard
Copied
If I understood the problem correctly, then:
var layer = activeDocument.layers.getByName('Hairs_TopNose'),
items = layer.pathItems,
i = items.length,
check = false;
while (i--) {
if (items.filled) {
items.filled = false;
check = true;
}
}
if (check) alert('Fill on Paths - Removed!');
else alert('Fill on Paths - Not found!');
Copy link to clipboard
Copied
@Alexander Ladygin, check is a variable, correct ?
What was wrong with the code approach I took; the loop is what I can see ?
Copy link to clipboard
Copied
Try putting the if statement inside of the for loop, this code assumes that none of the path items are grouped:
// get a reference to all the path items in the layer,
// doesn't include any paths that are in groups or sublayers
var paths = layer.pathItems;
var curPath;
// loop through each index in the array of path items
for( var i = 0, ii = paths.length; i<ii; i++ ) {
// get a reference to the current path
curPath = paths;
// check if it has a fill color
if( curPath.filled == true ) {
// remove its fill color
curPath.filled = false;
}
}
If you are using CS6 or newer, the 'executeMenuCommand' might also be a good approach:
#target illustrator
function test() {
// get references to the document and the layer
var doc = app.activeDocument;
var layer = doc.layers.getByName( "Hairs_TopNose" );
// clear any current selections
doc.selection = null;
// select all the art on the layer and unlock and show it
layer.hasSelectedArtwork = true;
app.executeMenuCommand( "unlockAll" );
app.executeMenuCommand( "showAll" );
// reset the selection and clear any fill colors
layer.hasSelectedArtwork = true;
doc.defaultStrokeColor = new NoColor();
// clear the selection
doc.selection = null;
}
test();
Copy link to clipboard
Copied
This is altered to what Alexander Ladygin posted, except there is an error on line 4; which is odd because it's identical to the same line in his code ?
var curDoc = app.activeDocument;
var lyr = curDoc.layers.getByName("Hairs_TopNose");
var pathss = lyr.hasSelectedArtwork;
var pth = layer.pathItems;
var patth = pth.length;
var verify = false;
while (i--) {
if (patth.filled) {
patth.filled=false;
verify=true;
}
};if (verify) alert("Fill on paths removed");
else alert("Fill on paths not removed");
Copy link to clipboard
Copied
Change 'layer.pathItems' to 'lyr.pathItems', I hate when that happens!
Copy link to clipboard
Copied
Thanks, although now i the variable in the while loop is undefined ?
Copy link to clipboard
Copied
change the line:
var patth = pth.length;
to
var i = pth.length;
Copy link to clipboard
Copied
and in the if statement you have the wrong var as well.
while (i--) {
if (patth.filled) {
patth.filled=false;
use pth not patth.
pth is the array of path items
patth is the number of items in the array.
Copy link to clipboard
Copied
Qwertyfly...You mean var i is now the number of items in the array and pth is the list of the path items
Qwertyfly...Thank you and thank you to everyone who helped as well
Copy link to clipboard
Copied
try this.
renamed the variables so it makes more sense.
var myDoc = app.activeDocument;
var myLayer = myDoc.layers.getByName("Hairs_TopNose");
// the line here was not used
var myPaths = myLayer.pathItems;
var myPathQty = myPaths.length;
var verify = false;
var i = myPathQty;
while (i--) {
if (myPaths.filled) {
myPaths.filled=false;
verify=true;
}
};
if (verify) alert("Fill on paths removed");
else alert("Fill on paths not removed");