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

changing or scaling gradient length in javascript

Explorer ,
Nov 07, 2014 Nov 07, 2014

Copy link to clipboard

Copied

Hi,

I am trying to scale or change the length of a gradient fill. I managed to rotate it using the trick with .rotate without changing the shape, but I can't get the equivalent working with changing the length of the gradient - it just doesn't do anything!

I am on Illustrator 18 using JavaScript.

pathItem.fillColor.length doesn't work, and neither does .resize!

TOPICS
Scripting

Views

2.0K

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 , Nov 17, 2014 Nov 17, 2014

indeed this is a very good question, it's been asked several times...this time based on the rotate trick Is it possible to transform a selected gradient in javascript? I got some results (trial and error), I'm not sure what's happening though, the script seems to be unable to transform a gradient two times, here's what I've got.

 

// transform gradients findings

// select a path item with a gradient applied to it before running the script

 

var idoc = app.activeDocument;

var ipath =  idoc.select

...

Votes

Translate

Translate
Adobe
Guide ,
Nov 11, 2014 Nov 11, 2014

Copy link to clipboard

Copied

I like this question.

I have been playing a little with it and it has me stumped.

in the javascript reference it states we should be able to set the Length, Angle, Origin etc of a gradient object.

a statement such as:

alert(pathItem.fillColor.origin);

works fine and displays the origin, this also works with length and Angle.

But when you try to set these values it does not work.

it says nothing about it being read only.

Does anyone have any light to shed on this???

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
Explorer ,
Nov 12, 2014 Nov 12, 2014

Copy link to clipboard

Copied

Hi, thanks for your response! What I don't get is why .resize doesn't work when .rotate does!

I came up with a workaround though - I was thinking I would have a path with the gradient the way I want it, then use a script to copy it behind the other shapes, one by one, and use the top shape in each group as a clipping mask, if you follow what I mean.

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
Explorer ,
Nov 12, 2014 Nov 12, 2014

Copy link to clipboard

Copied

Maybe one should report the problems as a bug btw!    

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 ,
Nov 12, 2014 Nov 12, 2014

Copy link to clipboard

Copied

I Was thinking about that. But it makes the art a lot more complex. Especially if you want stroked shapes.

it should be simple.

I am happy to report a bug. But need to make sure it is a bug and not just something I'm not doing correctly.

Not it that it makes a lick of difference. If they paid any attention at all we would be able to run scripts from actions. Without having it break on restart!

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
Explorer ,
Nov 12, 2014 Nov 12, 2014

Copy link to clipboard

Copied

I just reported it as a bug - it probably doesn't hurt if you do it too. I didn't bother creating a test case - the read-onliness of those properties has been widely documented in the forums...    

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 ,
Nov 12, 2014 Nov 12, 2014

Copy link to clipboard

Copied

I added a bug report on this, if these options are read-only, then the least they could do is say so.

sadly the scripting documentation is far from extensive.

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 ,
Nov 17, 2014 Nov 17, 2014

Copy link to clipboard

Copied

indeed this is a very good question, it's been asked several times...this time based on the rotate trick Is it possible to transform a selected gradient in javascript? I got some results (trial and error), I'm not sure what's happening though, the script seems to be unable to transform a gradient two times, here's what I've got.

 

// transform gradients findings

// select a path item with a gradient applied to it before running the script

 

var idoc = app.activeDocument;

var ipath =  idoc.selection[0];

var fillcolor = ipath.fillColor;

 

 

ipath.filled = false; // remove previous gradient transformations, to be able to apply new ones ??

 

 

ipath.fillColor = fillcolor; // re apply the same gradient color, without transformations.

ipath.fillOverprint = ipath.fillOverprint; // without this, the gradient won't move or scale, but it does rotate ??

 

 

var moveMatrix = app.getTranslationMatrix(50, 0);

var scale_moveMatrix = app.concatenateScaleMatrix (moveMatrix, 75, 50);

var move_scale_rotateMatrix = app.concatenateRotationMatrix (scale_moveMatrix, 15);

 

 

ipath.transform(move_scale_rotateMatrix,false,false,true,false,0, Transformation.CENTER);


 

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
Explorer ,
Nov 18, 2014 Nov 18, 2014

Copy link to clipboard

Copied

Thanks, I'll give it a shot and see if it works!

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 ,
Nov 18, 2014 Nov 18, 2014

Copy link to clipboard

Copied

This is great, how ever did you decide to try ipath.fillOverprint = ipath.fillOverprint;

I found the script can edit the object again, if you change angle say to 25° and re-run then it re-fills and transforms to the 25°.

What I can't work out is how to read the newly set angle etc...

is there a way you know of to get the values of the matrix.

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 ,
Nov 18, 2014 Nov 18, 2014

Copy link to clipboard

Copied

using overprint wasn't my idea, it was on the link I posted, I wouldn't have thought of it either.

you might be able to work out the math in matrix values, all I know about it (not much), I got from here

senocular.com

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 ,
Nov 18, 2014 Nov 18, 2014

Copy link to clipboard

Copied

in your link he uses ipath.fillOverprint = false;

not ipath.fillOverprint = ipath.fillOverprint;

but I tried setting it to false in your script and it still works.

Matrices look like quite a headache, could be that I've had a long day and my brain is a little soft right now.

I'll have to have a read at some point as they could be quite useful.

Thanks Carlos.

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 ,
Nov 18, 2014 Nov 18, 2014

Copy link to clipboard

Copied

I tried to keep the original overprint setting whether true of false...I don't remember if it worked, I tried sooo many things that day, I got frustrated, nothing seemed to work.

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 ,
Nov 19, 2014 Nov 19, 2014

Copy link to clipboard

Copied

ahhh the "joys" of coding...!

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 ,
Nov 19, 2014 Nov 19, 2014

Copy link to clipboard

Copied

hahaha, right, the joys of coding...Illustrator

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

What i do find weird in this method. If you reset the angle back to 0 deg. The gradient doesnt match the angle?!
Noticed how the angle is 0 but it still angled in a certain degree?!

gradient angle reset to 0gradient angle reset to 0

What is also weird, if you do an Object > rotate. I see both the path and gradient angle get a rotation. Yet the gradient gizmo is parellel to the path object?!?!
both path angle and gradient angle show an angle of 15?!both path angle and gradient angle show an angle of 15?!

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 ,
Sep 04, 2024 Sep 04, 2024

Copy link to clipboard

Copied

LATEST

I came back to this post again. Found an easy example on the documentation api page. This one runs just fine, no issue. 
https://ai-scripting.docsforadobe.dev/jsobjref/Matrix.html#jsobjref-matrix

I noticed your example gets illustrator funky and acting weird.

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
Explorer ,
Nov 19, 2014 Nov 19, 2014

Copy link to clipboard

Copied

I tried Carlos snippet, which i modified for the case I had - and it worked fine - thanks!    

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 ,
Nov 19, 2014 Nov 19, 2014

Copy link to clipboard

Copied

great!!, glad to help

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