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

Dynamic Color Table Builder

Engaged ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

I am trying to build a script that will look at the layers of the document in order to know how to build a "color table".

So here are all the options that would be available:

So let's say my document only contains LAYER 2, LAYER 7, and LAYER 13...the table would look like this...

I am not sure how to increment the lines to get the spacing dynamically. Then I am also struggling with passing the desired swatch color to the line.

Here is what I have so far.... any help/guidance would be appreciated!

#target illustrator-23

var doc = app.activeDocument;

var allLayers = doc.layers;

var allSwatches = doc.swatches;

var incUp = 457;

var incDown = 466;

function makeALine() {

    var colorTableLine = doc.pathItems.add();

    colorTableLine.filled = false;

    colorTableLine.stroked = true;

    colorTableLine.strokeWidth = 5;

    colorTableLine.strokeJoin = StrokeJoin.MITERENDJOIN;

    colorTableLine.strokeCap = StrokeCap.BUTTENDCAP;

    colorTableLine.setEntirePath([

        [220, (incDown += 9)],

        [270, (incDown)]

    ]);

}

function tableAroundLine() {

    var tableLine = doc.pathItems.add();

    tableLine.filled = false;

    tableLine.stroked = true;

    tableLine.strokeWidth = 0.75;

    tableLine.strokeJoin = StrokeJoin.MITERENDJOIN;

    tableLine.strokeCap = StrokeCap.BUTTENDCAP;

    tableLine.setEntirePath([

        [220, (incUp += 12)],

        [270, (incUp)]

    ]);

}

for (i = 0; i < allLayers.length; i++) {

    if (allLayers.name == "Layer 2") {

        tableAroundLine();

        makeALine();

        tableAroundLine();

        colorTableLine.strokeColor.spot == "[Spot 032 (Red)]";

    }

    if (allLayers.name == "Layer 7") {

        tableAroundLine();

        makeALine();

        tableAroundLine();

        colorTableLine.strokeColor.spot == "[Spot 464 (Brown)]";

    }

    if (allLayers.name == "Layer 13") {

        tableAroundLine();

        makeALine();

        tableAroundLine();

        colorTableLine.strokeColor.spot == "[Spot 865 (Blue)]";

    }

}

TOPICS
Scripting

Views

325

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
Valorous Hero ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Hello!

First, I would suggest you use a stored template which gets your color table artwork and has a way of making your scripting duties much easier. For example, your table rows can be made of various shapes and have one text frame all grouped in a group which you can then easily duplicate and put underneath the previous one's bounding box.

Second, the color is so strange in Illustrator, so it takes questions like these to help build experience with all these quirks. In your case, you have to assign a SpotColor kind of color to the fillColor first.

Unfortunately they don't give you a SpotColors collection and all that looks closest is the Document.spots collection.

So first the difference is that a 'spot' is what we would naturally refer to as a document's 'spot color' but it's actually an object with all the attributes a spot color would be expected to have, minus the tint. The tint is actually specified inside a "SpotColor" object along side the .spot property.

What you must do is get a reference to the SpotColor and not the 'spot' by using the swatches collection and the name of your spot in question.

    myPath.fillColor = doc.swatches["TEST"].color;

This snippet works on the assumption that you have a spot color swatch in the document called "TEST". It assigns the SpotColor object which is contained inside the .color property of a document's swatch.

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 ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

LATEST

To avoid 14 'if-clauses' in for-loop you can try (and rebuild) the following snippet

var aDoc = app.activeDocument; 

var theLay = doc.layers; 

var layersPresent = {

    "Layer 1":"Schwarz",

    "Layer 2":"CMYK Rot",

    "Layer 3":"CMYK Blau"

};

//var layersOther = {

//    "Layer 13":"CMYK Cyan"

//};

for (var re in layersPresent) {

try {

    var aLay = aDoc.layers.getByName(re);

    var aCol = aDoc.swatches.getByName (layersPresent[re]);

    // only for example - create texframes with layer names and given colors

    var aTF = aLay.textFrames.add ();

    aTF.contents = aLay.name;

    aTF.textRange.characterAttributes.fillColor = aCol.color;

    }

catch (e) {}

};

Have fun

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