Duplicate/Move Layer, Outline Text, then Remove Strokes & Change Fill to Black
The ultimate goal of this script is to create a sort of plain black text version of a copy layer (with text that sometimes has various effects/appearances applied).
I've got a multi-part script I'm trying to write that will do a few things in order. I've got a few bits cobbled together from other scripts, but it's not entirely working and there's some bits of functionality I don't know how to fit in there. It's actually a bit of a mess and I'm sure there must be a more efficient way to go about it. Could anybody take a look and either point me in the right direction or (if someone had the time) create a more efficient version of this.
What I need the script to do:
1. Lock all Layers
2. Duplicate Layer "SOURCE"
3. Rename duped layer to "SOURCE APPROVAL" & hide all other layers
4. Move "SOURCE APPROVAL" layer to below "SOURCE" layer in layers palette
5. Outline all text on "SOURCE APPROVAL" layer
6. Select everything, remove all strokes, and change the Fill color of all objects (whether regular items or compound paths or grouped) to black (only on "SOURCE APPROVAL" layer)
What I've got so far is a giant mess that does some things, but not others. I haven't been able to get the layers to move to a specific point in the layers palette and I can't seem to affect compound paths to change their color or remove their strokes.
var docRef = app.activeDocument;
var myLayers = docRef.layers;
var layer = app.activeDocument.activeLayer;
var flatBlack= new CMYKColor()
flatBlack.black=100;
for (a=0; a<myLayers.length; a++){
myLayer = myLayers;
myLayer.locked = true;
}
#target illustrator
var ln = 'SOURCE';
var ol = docRef.layers.getByName(ln);
var nl = docRef.layers.add();
nl.name = ln+' APPROVAL';
for (var a = ol.pageItems.length-1; a >= 0; a--) {
ol.pageItems.duplicate(nl, ElementPlacement.PLACEATBEGINNING);
}
app.executeMenuCommand("selectall");
app.executeMenuCommand("ungroup");
app.executeMenuCommand("outline");
// Iterate through all path items
for (var i = 0; i < nl.pathItems.length; i++) {
with (nl.pathItems) {
if (filled == true) {
// If black exceeds maxBlack clip it to flat black (100%K)
fillColor = flatBlack;
}
if (stroked == true) {
stroked = false;
}
}
}
