Skip to main content
Inspiring
September 11, 2013
Answered

How to distinguish linear and radial gradients in Javascript

  • September 11, 2013
  • 1 reply
  • 661 views

Hey guys,

I've noticed that certain some scripts im using cant always target both linear and radial gradients. I was curious as to why that was and where the information about weather a gradient is linear or radial is stored or how it can be accessed. So far no luck.

This is what i have so far, it doesnt tell me anything beyond that a given pathItem has a "GradientColor." as it's fillColor I cant figure out the syntax to test if it's linear or radial.

#target illustrator

var doc = app.activeDocument

for(x=0; x<doc.pathItems.length; x++){

alert (doc.activeLayer.pathItems[0].fillColor);

}

I've tried attaching the following to the end but it always returnes undefined.

.type

.typename

.gradient

.GradientType

and anything else i could find in the refrence guide for CS6.

Any advice or direction would be greatly appreciated.

This topic has been closed for replies.
Correct answer CarlosCanto

you're close, you need to target the actual gradient object to get its properties

alert (doc.activeLayer.pathItems[0].fillColor.gradient.type);

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
September 11, 2013

you're close, you need to target the actual gradient object to get its properties

alert (doc.activeLayer.pathItems[0].fillColor.gradient.type);

Inspiring
September 11, 2013

Awesome!

Thank's Carlos!

Ah ya that makes sense, I knew i was close