Skip to main content
Inspiring
February 4, 2013
Answered

Changing the angle of a linear gradient fill

  • February 4, 2013
  • 1 reply
  • 1623 views

Hi friends

Suppose I have an object filled with a linear gradient. This object is the only selected. I just would like to change the angle of the gradient to 25 degrees. So I think I could do:

var doc = app.activeDocument

alert(doc.selection[0].fillColor.angle) // the result is the exact angle of the gradient fill of the selected object. Suppose 12 degrees.

//now the try to change:

doc.selection[0].fillColor.angle = 25.0

---

No errors are found by the Extended Script Toolkit..BUT...it does not change anything. As Illustrator reference manual does not say this property is read only, I think I could write.

Am I missing anything?

Thank you a lot for the help

Best Regards

Gustavo.

This topic has been closed for replies.
Correct answer pixxxelschubser

It's tricky.

// GradientBlackWhite_rotated.jsx

// requires an open document and one selected object

var newGradient = app.activeDocument.gradients.add();

var colorOfGradient = new GradientColor();

var myGradientAngle = 80;

colorOfGradient.gradient = newGradient;

doc.selection[0].fillColor = colorOfGradient;

/*Thanx to John Wundes for this -->*/doc.selection[0].rotate(myGradientAngle, false, false, true, false, Transformation.CENTER);

redraw();

alert("gedreht");

Have fun

1 reply

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
February 5, 2013

It's tricky.

// GradientBlackWhite_rotated.jsx

// requires an open document and one selected object

var newGradient = app.activeDocument.gradients.add();

var colorOfGradient = new GradientColor();

var myGradientAngle = 80;

colorOfGradient.gradient = newGradient;

doc.selection[0].fillColor = colorOfGradient;

/*Thanx to John Wundes for this -->*/doc.selection[0].rotate(myGradientAngle, false, false, true, false, Transformation.CENTER);

redraw();

alert("gedreht");

Have fun

Inspiring
February 5, 2013

Thank you for the tip.

Will adapt this code to my needs

Thank you a lot

Best Regards

Gustavo.