2 Replies Latest reply on Feb 9, 2017 4:28 PM by pixxxel schubser

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

    KiernanSanders

      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

        • 1. Re: Layer color typenames - any way to call these out in a script?
          Silly-V Adobe Community Professional

          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.

          • 2. Re: Layer color typenames - any way to call these out in a script?
            pixxxel schubser Level 5

            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