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!
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
...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???
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.
Copy link to clipboard
Copied
Maybe one should report the problems as a bug btw!
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!
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...
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.
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);
Copy link to clipboard
Copied
Thanks, I'll give it a shot and see if it works!
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.
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
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.
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.
Copy link to clipboard
Copied
ahhh the "joys" of coding...!
Copy link to clipboard
Copied
hahaha, right, the joys of coding...Illustrator
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?!
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?!?!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I tried Carlos snippet, which i modified for the case I had - and it worked fine - thanks!
Copy link to clipboard
Copied
great!!, glad to help