Copy link to clipboard
Copied
I am trying to apply a swatch to all pathItems on a certain layer. I have the code written to access the layer I want but I am not sure how to apply a specific swatch name to the pathItems on the layer that I want. In my code if the pathItem is on a layer named "651(Highways)" I want the swatch in my document labeled "651 (Blue Gray)" to be applied to all those pathItems.
Anyone help me out with that? I am sure it is simple but I have never done it before and not much luck Google'n it.
Here is my code....
#target illustrator
var doc = app.activeDocument;
var allLayers = doc.layers;
var allLines = doc.pathItems;
var allSwatches = doc.swatches;
// CHECK TO SEE WHAT LAYER PATH ITEMS ARE ON
for (var i = allLines.length-1; i >= 0; i--){
if (allLines.layer == "[Layer Rails/Feather Bars]"){
allLines.filled = false;
lineFormat();
blackStroke();
allLines.strokeWidth = 2.0;
}
else if (allLines.layer == "[Layer 651 (Highways)]"){
lineFormat();
allLines.strokeWidth = 1.1;
}
else {
//alert("Found line on " + allLines.layer);
}
}
function lineFormat(){
allLines.filled = false;
allLines.strokeWidth = 1.6;
allLines.strokeJoin = StrokeJoin.MITERENDJOIN;
allLines.strokeCap = StrokeCap.BUTTENDCAP;
}
function blackStroke(){
var blackLine = new GrayColor();
blackLine.gray = 100;
allLines.stroked = true;
allLines.strokeColor = blackLine;
}
try
allLines.fillColor = allSwatches['651 (Blue Gray)'].color;
Copy link to clipboard
Copied
try
allLines.fillColor = allSwatches['651 (Blue Gray)'].color;
Copy link to clipboard
Copied
That worked! Only thing I changed was .fillColor to .strokeColor
- allLines.strokeColor = allSwatches['651 (Blue Gray)'].color;
THANK YOU CARLOS!
Copy link to clipboard
Copied
Great, you're welcome
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more