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

How can I change the color of a gradient stop via code?

New Here ,
Jun 10, 2020 Jun 10, 2020

Copy link to clipboard

Copied

I managed to figure how to change the location using:

 

app.activeDocument.gradients[0].gradientStops[0].location = 50;

 

but I'm lost when it comes to changing its color.

Annotation 2020-06-10 230539.png

TOPICS
Scripting

Views

220

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 ,
Jun 10, 2020 Jun 10, 2020

Copy link to clipboard

Copied

LATEST

You access the first one through app.activeDocument.gradients[0].gradientStops[0].stopColor;

It will return either a Color or MixedInk. From there, you can change the color profile. Ie:

var firstStop = app.activeDocument.gradients[0].gradientStops[0].stopColor;
firstStop.space = ColorSpace.RGB;
firstStop.colorValue = [100, 20, 10];

Or you can assign it to a preexisting swatch, color, etc:

app.activeDocument.gradients[0].gradientStops[0].stopColor = app.activeDocument.swatches.itemByName("PredefinedSwatch");

 

 

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