Answered
Applying Swatch to item
I've seen numerous previous posts on this topic that seem to work, but I can not get mine to work.
I feel like I'm spoon-feeding it precisely what it needs, but it is not applying the '100% Black' Swatch.
var doc = app.activeDocument;
// Create a new window
var win = new Window('dialog', 'Apply Swatch');
// Create an edittext box and a button
var swatchName = win.add('edittext', undefined, '100% Black');
swatchName.preferredSize.width = 100;
var applyButton = win.add('button', undefined, 'Apply');
// Add a click event listener to the button
applyButton.onClick = function() {
// Get the name of the swatch from the edittext box
var name = swatchName.text;
// Get all swatches in the document
var swatches = app.activeDocument.swatches;
// Find the swatch with the specified name
for (var i = 0; i < swatches.length; i++) {
alert(swatches[i].name);
if (swatches[i].name == name) {
// Apply the swatch as the fill color of the selected object
alert('swatch ' + swatches[i].name + ' applied');
doc.selection[0].fillColor = swatches[i].color;
break;
}
}
win.close();
}
// Show the window
win.show();Any help is appreciated!
