Gradient
Gradient
Section titled “Gradient”gradient
Description
Section titled “Description”A gradient definition contained in a document. Scripts can create new gradients.
Properties
Section titled “Properties”Gradient.gradientStops
Section titled “Gradient.gradientStops”gradient.gradientStops
Description
Section titled “Description”The gradient stops contained in this gradient.
GradientStops; read-only.
Gradient.name
Section titled “Gradient.name”gradient.name
Description
Section titled “Description”The gradient’s name.
String.
Gradient.parent
Section titled “Gradient.parent”gradient.parent
Description
Section titled “Description”The document that contains this gradient.
Document; read-only.
Gradient.type
Section titled “Gradient.type”gradient.type
Description
Section titled “Description”The kind of the gradient, either radial or linear.
Gradient.typename
Section titled “Gradient.typename”gradient.typename
Description
Section titled “Description”The class name of the referenced object.
String; read-only.
Methods
Section titled “Methods”Gradient.remove()
Section titled “Gradient.remove()”app.activeDocument.gradients[index].remove()
Description
Section titled “Description”Removes the referenced object from the document.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Creating and applying a gradient
Section titled “Creating and applying a gradient”// Creates a new gradient in current document then applies the gradient to the frontmost path item
if (app.documents.length > 0) { // Create a color for both ends of the gradient var startColor = new RGBColor(); startColor.red = 0; startColor.green = 100; startColor.blue = 255;
var endColor = new RGBColor(); endColor.red = 220; endColor.green = 0; endColor.blue = 100;
// Create a new gradient // A new gradient always has 2 stops var newGradient = app.activeDocument.gradients.add(); newGradient.name = "NewGradient"; newGradient.type = GradientType.LINEAR;
// Modify the first gradient stop newGradient.gradientStops[0].rampPoint = 30; newGradient.gradientStops[0].midPoint = 60; newGradient.gradientStops[0].color = startColor;
// Modify the last gradient stop newGradient.gradientStops[1].rampPoint = 80; newGradient.gradientStops[1].color = endColor;
// construct an Illustrator.GradientColor object referring to the newly created gradient var colorOfGradient = new GradientColor(); colorOfGradient.gradient = newGradient;
// get first path item, apply new gradient as its fill var topPath = app.activeDocument.pathItems[0]; topPath.filled = true; topPath.fillColor = colorOfGradient;}