Skip to main content
femkeblanco
Legend
Jan 17, 2021 2:13 AM UTC
Answered

Unable to change angle of gradient

gradientColor has an angle property, which I presume corresponds to or is similar to the Angle in the Gradient panel. Default is 0 and the gradient is horizontal. To make the gradient vertical, I tried assigning -90 (and 90), but nothing happens. If I print gradientColor properties, it shows angle is -90, but if I print fillColor properties, it shows angle is 0. What could be the problem? (I don't know if the origin property is relevant, but that doesn't seem to stick either. Interestingly, if I set Angle to -90 in the Gradient panel and then run the script, the gradient is vertical; but if I close the Gradient panel, open a new document and then run the script, the gradient is horizontal.)

 

Thanks in advance.

var w = 250, h = 250;
var d = app.activeDocument.artboards[0].artboardRect;
var paths = app.activeDocument.pathItems;
var rect1 = paths.rectangle(d[3]/2+h/2, d[2]/2-w/2, w, h);
rect1.stroked = false;
var startColor = new CMYKColor();
var endColor = new CMYKColor();
endColor.cyan = 100;
var gradient1 = activeDocument.gradients.add();
gradient1.type = GradientType.LINEAR;
gradient1.gradientStops[0].color = startColor;
gradient1.gradientStops[1].color = endColor;
var gradientColor1 = new GradientColor();
gradientColor1.gradient = gradient1;
gradientColor1.origin = [ d[2]/2, d[3]/2+h/2 ];
gradientColor1.length = h;
gradientColor1.angle = -90;
rect1.fillColor = gradientColor1;
gradientColor1 properties:
origin - 297.64013671875,-295.94482421875
angle - -90
length - 250
hiliteAngle - 0
hiliteLength - 0
matrix - [Matrix]
gradient - [Gradient Untitled Gradient]
typename - GradientColor

rect1.fillColor properties:
origin - 172,-420
angle - 0
length - 250.00048828125
hiliteAngle - 0
hiliteLength - 0
matrix - [Matrix]
gradient - [Gradient Untitled Gradient]
typename - GradientColor

 

This topic is closed to new replies. Start a new post to keep the conversation going.
m1b
m1bCorrect answer
Community Expert
Jan 17, 2021 5:41 AM UTC

Hi @femkeblanco, I can confirm the same issue. The angle of the GradientColor doesn't seem to do anything and, for me, stays set to zero. But I do notice that the matrix of the GradientColor does change to reflect a rotation. See here:

 

// item is a square with grad 0-100K L to R (angle actually zero!)
var item = app.activeDocument.selection[0];

/*
Angle is zero:
[GradientColor].angle = 0
Right now these are matrix values:
[Matrix].mValueA = 1
[Matrix].mValueB = 0
[Matrix].mValueC = 0
[Matrix].mValueD = 1
[Matrix].mValueTX = 0
[Matrix].mValueTY = 0
*/

//rotate only the gradient 45 degrees
item.rotate(45, false, false, true, false, Transformation.CENTER);

/*
Angle still says zero:
[GradientColor].angle = 0
Now the matrix is:
[Matrix].mValueA = 0.70710676573224
[Matrix].mValueB = 0.70710679664086
[Matrix].mValueC = -0.70710679664086
[Matrix].mValueD = 0.70710676573224
[Matrix].mValueTX = -252.081524926269
[Matrix].mValueTY = -891.421382509637
*/

 

- Mark

6 replies

CarlosCanto
Community Expert
Community Expert
Jan 17, 2021 9:46 PM UTC

It's a long standing bug since at least 2008. 

Translate
femkeblanco
Legend
Jan 17, 2021 10:45 PM UTC

Thanks for confirming.  I presumed I was doing something wrong. 

Translate
CarlosCanto
Community Expert
Community Expert
Jan 17, 2021 11:11 PM UTC
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jan 17, 2021 5:41 AM UTC

Hi @femkeblanco, I can confirm the same issue. The angle of the GradientColor doesn't seem to do anything and, for me, stays set to zero. But I do notice that the matrix of the GradientColor does change to reflect a rotation. See here:

 

// item is a square with grad 0-100K L to R (angle actually zero!)
var item = app.activeDocument.selection[0];

/*
Angle is zero:
[GradientColor].angle = 0
Right now these are matrix values:
[Matrix].mValueA = 1
[Matrix].mValueB = 0
[Matrix].mValueC = 0
[Matrix].mValueD = 1
[Matrix].mValueTX = 0
[Matrix].mValueTY = 0
*/

//rotate only the gradient 45 degrees
item.rotate(45, false, false, true, false, Transformation.CENTER);

/*
Angle still says zero:
[GradientColor].angle = 0
Now the matrix is:
[Matrix].mValueA = 0.70710676573224
[Matrix].mValueB = 0.70710679664086
[Matrix].mValueC = -0.70710679664086
[Matrix].mValueD = 0.70710676573224
[Matrix].mValueTX = -252.081524926269
[Matrix].mValueTY = -891.421382509637
*/

 

- Mark

Translate
femkeblanco
Legend
Jan 17, 2021 10:47 AM UTC

Thanks @m1b. I was not mindful of the fact that one could use rotate() to rotate the gradient by itself. That practically solves the problem. (Although the angle mystery remains.) Thanks again.

Translate