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

Layer color typenames - any way to call these out in a script?

New Here ,
Feb 09, 2017 Feb 09, 2017

Copy link to clipboard

Copied

I have marginal experience with coding and no experience with Javascript at all, but I'm trying to write a layer setup script in ExtendScript Toolkit to save time when starting a new document. I know that I can set layerColor as a new RGB color by using red/green/blue values. However, this results in the layer having a "custom" color in Illustrator, as opposed to one of the predefined colors, e.g. light blue, light red, green, etc, even if the "custom" defined values match the values of the predefined color. That's not really a problem per se, but I was curious if there is a way to set the RGB value for layerColor to one of the predefined colors using a "typename" value, which I found in the Illustrator Scripting Reference for Javascript.

I tried to do that, but no matter that I put in for the typename value, Illustrator sets the layer color to black. Not "custom" black, but predefined black, so it seems to be doing something partially like I want it to. I'm wondering if there's a reference somewhere to tell me what typename string I could put in to get Illustrator to pick the corresponding predefined layer color? Or, is it just defaulting to predefined black because it doesn't understand what I've entered for the typename value?

Hopefully that made some kind of sense; I don't have much background in describing coding accurately!

Screen Shot 2017-02-09 at 12.00.44 PM.pngScreen Shot 2017-02-09 at 12.01.10 PM.png

TOPICS
Scripting

Views

818

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 ,
Feb 09, 2017 Feb 09, 2017

Copy link to clipboard

Copied

Unfortunately, it appears that "Custom" is all we can do. The 'typename' property that you experimented with is actually read-only, so the 'pre-defined' Black color may be a result of the script not working properly past that line.

What I tried was setting one layer's color to another layer's color so that it should be the exact same one, and it still came out Custom.

Next I tried to record an action and see if the color was captured, and it was not.

It seems to me that their 'pre-defined' colors are one-way only: they appear in the dropdown list as a convenience but have no standing outside of the Layers dialog box.

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 ,
Feb 09, 2017 Feb 09, 2017

Copy link to clipboard

Copied

Hi KiernanSanders​,

there is no typename property for RGBColor.

As Silly-V​ said before:

all what we can give you with Javascript is a (similar) user defined color

var aDoc = app.activeDocument;

var aLay = aDoc.layers[0];

var layerColor = new RGBColor();

layerColor.red = 78.7;

layerColor.green = 78.7;

layerColor.blue = 255;

aLay.name = "source";

aLay.color = layerColor;

var newLayer = activeDocument.layers.add();

layerColor.red = 255;

layerColor.green = 78.7;

layerColor.blue = 255;

newLayer.name = "built";

newLayer.color = layerColor;

var newLayer = activeDocument.layers.add();

layerColor.red = 78.7;

layerColor.green = 127.5;

layerColor.blue = 255;

newLayer.name = "final";

newLayer.color = layerColor;

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
Engaged ,
Apr 22, 2019 Apr 22, 2019

Copy link to clipboard

Copied

LATEST

var doc = app.documents.add(); 

var layers=["MARKS","PRINT","CUT"]

app.activeDocument.layers[0].name="MARGINS";

var layerColor = new RGBColor(); 

layerColor.red = 255; 

layerColor.green = 79; 

layerColor.blue = 255; //Magenta

app.activeDocument.layers[0].color=layerColor;

var layerColors={

    color0:{

        red:255,

        green:78,

        blue:79///Light Red

        },

    color1:{

         red:79,

        green:128,

        blue:255 ///Blue

        },

    color2:{

        red:79,

        green:255,

        blue:79 ///Green

        }

    }

for(i in layers){

    var newLayer=app.activeDocument.layers.add();

    newLayer.name=layers;

    var layerColor = new RGBColor();

    var layerValue="color"+i;

    layerColor.red = layerColors[layerValue]["red"]; 

    layerColor.green = layerColors[layerValue]["green"]; 

    layerColor.blue = layerColors[layerValue]["blue"];

    newLayer.color=layerColor

    }

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