Copy link to clipboard
Copied
I'm looking for a way to automate a task in illustrator
I have several files with colours pallets and swatches, mostly gradients ( I mean thousands of them)
Id like my scrip to do this :
- create a grid of 100 x 100 pixel squares spaced by 20 pixels each
assign each square to a different swatches
so the end result will be a grid of squares, with each one of them has a different swatches that reflect my Swatch panel library for this document
is it possible to automate this via actions or scripts ? it is out of my knowledge base and I haven't found any automation process on YouTube or elsewhere on the internet
Thx
Ps here is an example where I did it manually by selecting a shape and clicked on a swatch
var doc = app.activeDocument;
var n = doc.swatches.length - 2;
var counter = 2;
var w = h = 100;
var top = 0;
for (var i = 0; i < n / 10; i++) {
var left = 0;
for (var j = 0; j < 10; j++) {
if (counter < n + 2) {
var square = doc.pathItems.rectangle(top, left, w, h);
square.fillColor = doc.swatches[counter].color;
counter += 1;
left += w + 20;
}
}
top -= h + 20;
}
Copy link to clipboard
Copied
EDIT :
the script from John Wundes renderSwatchLegend.jsx seems to be very close to what I'm trying to archive.
Exept that it will create swatches extracted from physical obj on the canvas.
While in my case, I have no objects in the file, only swatches, and I want to create the objects and assign each of them to a different swach.
any tips ?
Copy link to clipboard
Copied
Do you know how many total squares you need? Can you fill a page with more and go back and delete.
Record an action to make one square then duplicate to the right, select all then power duplicate (Command D).
After that run your script for random colors in your swatches.
Copy link to clipboard
Copied
Thx for the help but this is not what I am asking for. Maybe I was not clear
Lets skip the grid part, I know how to do that, easy stuff.
What I want to automate is :
Assing each shape a color, from my Swatch palette
I'm basically trying to create a visible swatchbook on the artboard to reflect what are the actual swatches present in the document.
Going from A to B ( see attachment)
Copy link to clipboard
Copied
var doc = app.activeDocument;
var n = doc.swatches.length - 2;
var counter = 2;
var w = h = 100;
var top = 0;
for (var i = 0; i < n / 10; i++) {
var left = 0;
for (var j = 0; j < 10; j++) {
if (counter < n + 2) {
var square = doc.pathItems.rectangle(top, left, w, h);
square.fillColor = doc.swatches[counter].color;
counter += 1;
left += w + 20;
}
}
top -= h + 20;
}
Copy link to clipboard
Copied
Thank you !!
Exactly what i was looking for
I wish I could code sometimes haha 😄