Skip to main content
Inspiring
Jul 2, 2024 3:40 AM UTC
Answered

How to select a gradient by name

To select a graidnet for a pathItem in a layer I would do this:

colLayer.fillColor = gradColor;

gradColor being a new GradientColor()

How would I be able to select a preexisitng gradient to fillColor?

In example using:

app.activeDocument.gradients[0]

So something like:

colLayer.fillColor = app.activeDocument.gradients[0]
This topic is closed to new replies. Start a new post to keep the conversation going.
m1b
m1bCorrect answer
Community Expert
Jul 2, 2024 4:53 AM UTC

Hi @OhmsG, if it is a swatch in the document, you can do this:

var doc = app.activeDocument;
var swatch = doc.swatches.getByName('MyGradient');

doc.pageItems[0].fillColor = swatch.color;

 

If it isn't a swatch, but is already a fillColor of another page item, you can do this:

var doc = app.activeDocument;
var myGradientColor = doc.pageItems[1].fillColor;

doc.pageItems[0].fillColor = myGradientColor;

 - Mark

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jul 2, 2024 4:53 AM UTC

Hi @OhmsG, if it is a swatch in the document, you can do this:

var doc = app.activeDocument;
var swatch = doc.swatches.getByName('MyGradient');

doc.pageItems[0].fillColor = swatch.color;

 

If it isn't a swatch, but is already a fillColor of another page item, you can do this:

var doc = app.activeDocument;
var myGradientColor = doc.pageItems[1].fillColor;

doc.pageItems[0].fillColor = myGradientColor;

 - Mark

Translate
OhmsGAuthor
Inspiring
Jul 2, 2024 5:26 AM UTC

So awesome, thank you!

Translate