Skip to main content
Known Participant
April 15, 2009
Question

I need a way to randomly rotate gradient fills.

  • April 15, 2009
  • 1 reply
  • 2201 views

I have a bunch of shapes that I would like to fill with a simple black to white gradient that is rotated at different angles. I tried to create a pattern and utilize the transform each option but it does not let me rotate only the pattern, it wants to rotate the entire vector. Is this something that could be done with a script?

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
April 16, 2009

It seems this might work:

#target illustrator

var myDocument = app.activeDocument;

var theItem = myDocument.pathItems[0];

theItem.rotate(Math.random()*360, false, false, true, false);

c.pfaffenbichler
Community Expert
Community Expert
April 16, 2009

I had left out a clause to adress more than the topmost object, so this should rotate the gradients of all the objects in a selection or a document:

#target illustrator

var myDocument = app.activeDocument;

if (myDocument.selection.length == 0) {

for (var m = 0; m < myDocument.pathItems.length; m++) {

var theItem = myDocument.pathItems;

theItem.rotate(Math.random()*360, false, false, true, false)

}

}

else {

var theSelection = myDocument.selection;

for (var m = 0; m < theSelection.length; m++) {

var theItem = theSelection;

theItem.rotate(Math.random()*360, false, false, true, false)

}

};

Actually I’m not that good with Scripting, especially for Illustrator, so hopefully someone more experienced will correct possible mistakes or shortcomings.

Larry G. Schneider
Community Expert
Community Expert
April 16, 2009

Works for me. Good job, Chris