Use a list of colour codes to auto-colour shapes in illustrator or photoshop?

Community Beginner ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Hello,

I have a list of 1000 colours in CMYK mode and an illustrator document with 1000 identical shapes. Is there a way I can auto colour each shape with a colour from my list? Perhaps a script?

Any advice would be greatly appreciated!

Thanks!

TOPICS
Actions and scripting

Views

89

Likes

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

Adobe Community Professional , Jun 01, 2022 Jun 01, 2022
With a list as a txt-file like this  a file like this results in this with the below Script; amend the path of the txt-file accordingly.  // change shape layers’ color based on list; // 2022, use it at your own risk; if (app.documents.length > 0) { var theList = "~/Desktop/colorList.txt"; var theColors = readPref (theList); var theLayers = collectShapeLayers (); var theCount = 0; for (var m = 0; m < theLayers.length; m++) { var thisColor = theColors[theCount].split...

Likes

Translate

Translate
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

1000 identical shapes in the same document? What kind of shape? Perhaps if each shape is on separate layer, my guess. My guess how things can be done. Wait for scripters @Stephen_A_Marsh @r-bin @Kukurykus @c.pfaffenbichler 

Likes

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 Beginner ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Thank you Bojan! 1,000 filled circles (spots). Yes, I could make 1,000 layers if there is a quick way of creating 1,000 layers? Also, I could do this project in Illustrator or Photoshop if it makes it easier? Thanks again!

Likes

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
Adobe Community Professional ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

If you do it in Illustrator please post on the Illustrator Forum. 

 

If you do it in Photoshop you should use 1000 individual Shape Layers. 

Could you provide a part of the list? How is it set up and what file format? 

Likes

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 Beginner ,
May 31, 2022 May 31, 2022

Copy link to clipboard

Copied

Thank you c.pfaffenbichler!

I can provide part of the list in whatever format/file you suggest?

Likes

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
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

In which format do you have it at current – txt, …? 

 

Does it make sense to just color Shape Layer 1 with color 1, Shape Layer 2 with color 2 etc. or do you intend randomization? 

Likes

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 Beginner ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

Thanks again for your help. I have attached an example of 9 colors which I will place in a grid. Randomization is not necessary and your suggestion of Shape Layer 1 with color 1 sounds fine!

Likes

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 Beginner ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

Hi, Thanks again for the help. I have attached a txt file with 9 colors as an example. I will place the 9 shapes in a grid. Randomization of colors not necessay. Your suggestion above sounds perfect!

Likes

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
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

With a list as a txt-file like this 

Screenshot 2022-06-01 at 14.06.18.png

a file like this

Screenshot 2022-06-01 at 14.03.40.png

results in this with the below Script; amend the path of the txt-file accordingly. 

Screenshot 2022-06-01 at 14.04.15.png

// change shape layers’ color based on list;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
    var theList = "~/Desktop/colorList.txt";
    var theColors = readPref (theList);
    var theLayers = collectShapeLayers ();
    var theCount = 0;
    for (var m = 0; m < theLayers.length; m++) {
        var thisColor = theColors[theCount].split(",");
        changeSolidColor(thisColor[0], thisColor[1], thisColor[2], thisColor[3], theLayers[m][1]);
        theCount++;
        if (theCount == theColors.length) {theCount = 0};
    };
    };
////////////////////////////////////
function collectShapeLayers () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theKind = layerDesc.getInteger(stringIDToTypeID('layerKind'));
if (theKind == 4) {theLayers.push([theName, theID])}
};
}
catch (e) {};
};
return theLayers;
};
////// change color of solid color layer //////
function changeSolidColor (the1, the2, the3, the4, theIdentifier) {
    // =======================================================
        var desc4 = new ActionDescriptor();
            var ref1 = new ActionReference();
//            ref1.putEnumerated ( stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
            ref1.putIdentifier ( stringIDToTypeID( "contentLayer" ), theIdentifier );
        desc4.putReference( charIDToTypeID( "null" ), ref1 );
            var desc5 = new ActionDescriptor();
                var desc6 = new ActionDescriptor();
                /*desc6.putDouble( charIDToTypeID( "Rd  " ), the1 );
                desc6.putDouble( charIDToTypeID( "Grn " ), the2 );
                desc6.putDouble( charIDToTypeID( "Bl  " ), the3 );
            desc5.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), desc6 );*/
                desc6.putDouble( stringIDToTypeID( "cyan" ), the1 );
                desc6.putDouble( stringIDToTypeID( "magenta" ), the2 );
                desc6.putDouble( stringIDToTypeID( "yellowColor" ), the3 );
                desc6.putDouble( stringIDToTypeID( "black" ), the4 );
        desc5.putObject( charIDToTypeID("Clr "), stringIDToTypeID("CMYKColorClass"), desc6 );
        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
        desc4.putObject( charIDToTypeID("T   "), idsolidColorLayer, desc5 );
        executeAction( charIDToTypeID("setd"), desc4, DialogModes.NO );
    };
////// read prefs file //////
function readPref (thePath) {
  if (File(thePath).exists == true) {
    var file = File(thePath);
    file.open("r");
    file.encoding= 'BINARY';
    var theText = file.read();
    file.close();
    return String(theText).split("\n")
//    return String(theText).split(",")
    }
  };

 

Likes

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 Beginner ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

Thank you very much for this! I tried replying twice earlier with a txt file but for some reason it did not post. Thank you for your effort. It seems exactly what I need. Greatly appreciated. Thank you again!

Likes

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
Adobe Community Professional ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

LATEST

You’re welcome, hope it works out. 

Likes

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