Copy link to clipboard
Copied
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
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].m
...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
It's a long standing bug since at least 2008.
Copy link to clipboard
Copied
Thanks for confirming. I presumed I was doing something wrong.
Copy link to clipboard
Copied
check this thread for a discussion about it
Copy link to clipboard
Copied
I find it strange that we can call the and see the attributes of a matrix but we cant feed one back into it. Thats is as stranger as the angle can be read but cant be changed by scripting?!