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[i].layer == "[Layer Rails/Feather Bars]"){ allLines[i].filled = false; lineFormat(); blackStroke(); allLines[i].strokeWidth = 2.0; } else if (allLines[i].layer == "[Layer 651 (Highways)]"){ lineFormat(); allLines[i].strokeWidth = 1.1; } else { //alert("Found line on " + allLines[i].layer); } } function lineFormat(){ allLines[i].filled = false; allLines[i].strokeWidth = 1.6; allLines[i].strokeJoin = StrokeJoin.MITERENDJOIN; allLines[i].strokeCap = StrokeCap.BUTTENDCAP; } function blackStroke(){ var blackLine = new GrayColor(); blackLine.gray = 100; allLines[i].stroked = true; allLines[i].strokeColor = blackLine; }