Copy link to clipboard
Copied
Hi I was hoping to create a color group that contents 128 color swatches from white to black, grey scale color. however I keep getting this error messgae 21
here is my code, please let me know if anyone can help, thank you!
// Specify the number of swatches you want to create
var numSwatches = 128;
// Create an empty array to store the swatches
var swatches = [];
// Loop through each swatch and calculate the brightness value
for (var i = 0; i < numSwatches; i++) {
var brightness = i * 1 / (numSwatches - 1);
// Create a new swatch with the brightness value
var newSwatch = new GrayColor();
newSwatch.gray = brightness;
swatches.push(newSwatch);
}
// Add the swatches to the swatches panel
for (var j = 0; j < swatches.length; j++) {
var newSpot = app.activeDocument.swatches.add(swatches[j]);
newSpot.name = "Swatch " + (j + 1);
}
// Select all the swatches
app.activeDocument.swatches["Swatch 1"].selected = true;
for (var k = 2; k <= swatches.length; k++) {
app.activeDocument.swatches["Swatch " + k].selected = true;
}
// Export the swatches as an ASE file
var aseFile = new File("~/Desktop/GrayScaleSwatches.ase");
app.activeDocument.swatches["Swatch 1"].parent.exportSelected(aseFile, ExportType.ASE);
Copy link to clipboard
Copied
Where did you get this Script?
Photoshop Documents have no swatches so how should this work?
Copy link to clipboard
Copied
Have you tried using ScriptingListener.plugin to record the process of creating a Color Swatch yet in order to wrap the AM-code in a function?