• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create color group and color swatches with scripting error 21

New Here ,
Apr 04, 2023 Apr 04, 2023

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);

TOPICS
Actions and scripting

Views

215

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 05, 2023 Apr 05, 2023

Copy link to clipboard

Copied

Where did you get this Script? 

Photoshop Documents have no swatches so how should this work? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2023 Apr 08, 2023

Copy link to clipboard

Copied

LATEST

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? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines