2 Replies Latest reply on Aug 12, 2017 10:35 AM by MBA-2-rae

    User to select fill layer colour

    bradleya17648820

      I currently have a fill layer function that creates a while layer.. simple

       

          function createFill() {
              var fillColor = new SolidColor();
              fillColor.rgb.red = 255;
              fillColor.rgb.green = 255;
              fillColor.rgb.blue = 255;
      
      
              var newLayer = doc.artLayers.add();
              newLayer.name = "fill " + (i + 1);
              doc.selection.fill(fillColor);
              newLayer.move(newLayer, ElementPlacement.PLACEAFTER);
      
      
              var fillLayer = doc.activeLayer;  
              fillLayer.move(doc.layers[doc.layers.length-1], ElementPlacement.PLACEAFTER);
          }
      

       

      Is there a way for the user to select a colour instead of hard coding it? Giving them the option of black or white?

       

      For example if the user was to use a logo as below with a white background it would not look so good. So it would be good to give them the option of a different colour for these situations

       

      Screen Shot 2017-07-17 at 20.58.44.png

        • 1. Re: User to select fill layer colour
          Chuck Uebele Adobe Community Professional & MVP

          Do you want only black or white - no other colors or shades of gray? If so, you can create a simple UI with radio buttons for them to select either black or white.

          • 2. Re: User to select fill layer colour
            MBA-2-rae Level 1

            perhaps this function helps:

             

            #target photoshop

             

            function runColorPicker() {

             

              defColor = app.foregroundColor

             

              try {

              var bytes;

              var rgb = app.foregroundColor.rgb;

              bytes = (rgb.red << 16) + (rgb.green << 8) + rgb.blue;

              bytes = $.colorPicker(bytes);

             

              if (bytes != -1) {

              var c = new SolidColor();

              c.rgb.red = (bytes >> 16);

              c.rgb.green = (bytes >> 8) & 0xFF;

              c.rgb.blue = bytes & 0xFF;

              }

              } catch (e) {alert(e)}

             

             

              return c;

            }

            // call PS ColorPicker

            var color1 = runColorPicker();

             

            // show result

            alert(color1.rgb.red + ' ' + color1.rgb.green + ' ' + color1.rgb.blue)