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

Automate color Swatches object

Participant ,
Jan 08, 2023 Jan 08, 2023

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


-
www.instagram.com/mugen_labz/
TOPICS
Scripting

Views

279

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

Guide , Jan 08, 2023 Jan 08, 2023
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;
}

Votes

Translate

Translate
Adobe
Participant ,
Jan 08, 2023 Jan 08, 2023

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 ? 


-
www.instagram.com/mugen_labz/

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 08, 2023 Jan 08, 2023

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

Screen Shot 2023-01-08 at 10.17.57 AM.jpg

 

After that run your script for random colors in your swatches.

 

 

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
Participant ,
Jan 08, 2023 Jan 08, 2023

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) 


-
www.instagram.com/mugen_labz/

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 08, 2023 Jan 08, 2023

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;
}

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
Participant ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

LATEST

Thank you !! 
Exactly what i was looking for 

I wish I could code sometimes haha 😄 

 


-
www.instagram.com/mugen_labz/

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