• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Unable to change angle of gradient

Guide ,
Jan 16, 2021 Jan 16, 2021

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.

Untitled.png

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

 

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 16, 2021 Jan 16, 2021

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 16, 2021 Jan 16, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2021 Jan 17, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2021 Jan 17, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2021 Jan 17, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2021 Jan 17, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 18, 2021 Aug 18, 2021

Copy link to clipboard

Copied

LATEST

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?!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines