Applying spot colour to selection help? Unlocking layer?
I've got a section of code (shown below) that creates two spot colours and applies the first to all white elements, this works as intended.
The second fill needs to be applied to the selection after offset path section of the script but doesn't seem to be working at filling anything.
I've tried a workaround that fills the selection by locking the first layer, creating a new layer, pasting in place and applying the fill. This works in applying the fill but then I'm unable to unlock the layer I locked previously anymore?
Ideally I'd just like to be able to apply the swatch 'Underbase' to the selection after the offset path.
Any ideas? Thank you in advance?
addSpot('White Overprint', 39, 0, 39, 0);
function addSpot(name, c, m, y, k) {
try {
swatch = app.activeDocument.swatches[name]; // if swatch exists....
addSpot(name += '1', c, m, y, k); // ...add 1 to swatch name
} catch (e) {
var newSpot = app.activeDocument.spots.add();
newSpot.name = name;
var newColor = new CMYKColor();
newColor.cyan = c;
newColor.magenta = m;
newColor.yellow = y;
newColor.black = k;
newSpot.colorType = ColorModel.SPOT;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
}
}
// Get the swatch called "White Overprint"
var swatch = app.activeDocument.swatches.getByName("White Overprint");
// Loop through all path items in the document
for (var i = 0; i < app.activeDocument.pathItems.length; i++) {
var pathRef = app.activeDocument.pathItems[i];
// Check if the path item's fill color is white
if (pathRef.fillColor.typename === "CMYKColor" && pathRef.fillColor.cyan == 0 && pathRef.fillColor.magenta == 0 && pathRef.fillColor.yellow == 0 && pathRef.fillColor.black == 0) {
pathRef.filled = true;
pathRef.fillColor = swatch.color;
}
}
///app.executeMenuCommand("OffsetPath v23");
var idoc = app.activeDocument;
var sel = idoc.selection[0];
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var offset = "-0.3";
// offset path Effect with Round Joins
var xmlstringOffsetPath = '<LiveEffect name="Adobe Offset Path"><Dict data="R mlim 4 R ofst value I jntp 0 "/></LiveEffect>'; // 0 = round, 1=bevel, 2=miter
xmlstringOffsetPath = xmlstringOffsetPath.replace("value", offset);
idoc.selection = null;
var dup = sel.duplicate(sel, ElementPlacement.PLACEAFTER);
try {
dup.filled = false;
} catch (e) {}
dup.selected = true; // select it before applying effects
// apply offset path Effect
dup.applyEffect(xmlstringOffsetPath);
app.redraw();
// expand appearance
app.executeMenuCommand('expandStyle');
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
app.executeMenuCommand('cut');
app.executeMenuCommand('AdobeLayerPalette2');
app.executeMenuCommand('pasteInPlace');
// Get Layer 1
var layer1 = app.activeDocument.layers.getByName("Layer 1");
// Lock Layer 1
layer1.locked = true;
addSpot('Underbase', 100, 0, 0, 0);
function addSpot(name, c, m, y, k) {
try {
swatch2 = app.activeDocument.swatches[name]; // if swatch exists....
addSpot(name += '1', c, m, y, k); // ...add 1 to swatch name
} catch (e) {
var newSpot = app.activeDocument.spots.add();
newSpot.name = name;
var newColor = new CMYKColor();
newColor.cyan = c;
newColor.magenta = m;
newColor.yellow = y;
newColor.black = k;
newSpot.colorType = ColorModel.SPOT;
newSpot.color = newColor;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
}
}
// Get the swatch called "Underbase"
var swatch = app.activeDocument.swatches.getByName("Underbase");
// Loop through all path items in the document
for (var i = 0; i < app.activeDocument.pathItems.length; i++) {
var pathRef = app.activeDocument.pathItems[i];
pathRef.filled = true;
pathRef.fillColor = swatch.color;
}
}
// Get Layer 1
var layer1 = app.activeDocument.layers.getByName("Layer 1");
// Lock Layer 1
layer1.locked = false;
app.executeMenuCommand('Selectall');
app.executeMenuCommand('group');
