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

Photoshop JavaScript fill layer creation question

New Here ,
Jul 04, 2015 Jul 04, 2015

You can probably guess what I'm trying to do by this snippet:

var docRef = app.activeDocument;  var layerRef = app.activeDocument.artLayers.add(); layerRef.kind = LayerKind.SOLIDFILL;

I want to script the creation of a fill layer (and then later designate color, remove mask, etc). I get this response from the ExtendScript Toolkit: "You can only change the layer's kind to text or normal"

I would have thought that there would be a way to pass arguments of some sort to the add()method of artLayers?! Am I missing something really simple? Thanks.

I know this can be done with actions but I would like to learn how to do this (seemingly) very simple task and build on it to create more complex, useful scripts.

Also, i don't know if this is important but I'm running Ps CC15, ES toolkit 4, and using script reference CC14

TOPICS
Actions and scripting
7.4K
Translate
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

Community Expert , Jul 05, 2015 Jul 05, 2015

I totally understand! I'm the same way. I want to know how things work, so I can better use them. Finding documentation on this stuff is difficult at best. The DOM information has a bit more documentation than the AM code. A while ago I was trying to figure out how to modify some AM code. I asked Jeff Tranberry about it, and he replied, "It's a dark art."

Unfortunately, I think AM code is the only way to create a solid fill layer, and it is the only way to do a lot of PS operations:

Translate
Adobe
Community Expert ,
Jul 04, 2015 Jul 04, 2015

If you just want a new layer that is a solid color  with no layer mask on it. Why not just add the layer and fill it with the color you want. Why do to add a solid fill adjustment layer remove the reveal all layer mask and rasterize it to a normal layer?

function newColorLayer(red,green,blue) {

newLayer = app.activeDocument.artLayers.add();

newLayer.name = red + "," +green + "," + blue;

newColor = new SolidColor;

newColor.rgb.red = red;

newColor.rgb.green = green;

newColor.rgb.blue = blue;

app.activeDocument.selection.selectAll();

app.activeDocument.selection.fill(newColor);

app.activeDocument.selection.deselect();

};

newColorLayer(128,128,128);

JJMack
Translate
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 ,
Jul 04, 2015 Jul 04, 2015

For solid fill layers and gradient fill layers, I use Scriptlistener. Then I put all that code into a function where I can pass the different traits of the shape. When you create the fill layer, make your colors number things you can find easy like 111 for red, 222 for green 66 for blue.

Translate
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 ,
Jul 04, 2015 Jul 04, 2015

Here's what the AM code would look like with an extra bit to remove the mask.

#target photoshop

makeSolidFill (234, 34, 12);//enter number here for color or use variables to set color

removeMask ()

function makeSolidFill(redC,greenC,blueC){

  // =======================================================

    var idMk = charIDToTypeID( "Mk  " );

        var desc15 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref4 = new ActionReference();

            var idcontentLayer = stringIDToTypeID( "contentLayer" );

            ref4.putClass( idcontentLayer );

        desc15.putReference( idnull, ref4 );

        var idUsng = charIDToTypeID( "Usng" );

            var desc16 = new ActionDescriptor();

            var idType = charIDToTypeID( "Type" );

                var desc17 = new ActionDescriptor();

                var idClr = charIDToTypeID( "Clr " );

                    var desc18 = new ActionDescriptor();

                    var idRd = charIDToTypeID( "Rd  " );

                    desc18.putDouble( idRd, redC);//Red variable

                    var idGrn = charIDToTypeID( "Grn " );

                    desc18.putDouble( idGrn, greenC);//green variable

                    var idBl = charIDToTypeID( "Bl  " );

                    desc18.putDouble( idBl, blueC );//blue variable

                var idRGBC = charIDToTypeID( "RGBC" );

                desc17.putObject( idClr, idRGBC, desc18 );

            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

            desc16.putObject( idType, idsolidColorLayer, desc17 );

        var idcontentLayer = stringIDToTypeID( "contentLayer" );

        desc15.putObject( idUsng, idcontentLayer, desc16 );

    executeAction( idMk, desc15, DialogModes.NO ); 

    }

function removeMask(){

    var idDlt = charIDToTypeID( "Dlt " );

        var desc21 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref5 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            var idChnl = charIDToTypeID( "Chnl" );

            var idMsk = charIDToTypeID( "Msk " );

            ref5.putEnumerated( idChnl, idChnl, idMsk );

        desc21.putReference( idnull, ref5 );

    executeAction( idDlt, desc21, DialogModes.NO );

    }

Translate
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
New Here ,
Jul 04, 2015 Jul 04, 2015

Thanks for the replies.

First off I feel like I should clarify that my problem isn't creating a layer that is filled with a color, if I needed that I would create a new layer and fill it myself. The issue is that I don't understand how to use this add() method for anything other than creating layerKind.NORMAL and layerKind.TEXT . I've googled as much as I can stand and the only solutions people have come up with (and thank you again for offering them) are to use AM code or to make a selection and fill it. I would really like to understand the Photoshop DOM and how it can be better leveraged but nobody seems to know something that I was initially feeling silly for not getting. In the photoshop scripting reference states the add() method of the artLayers object appears to accept no params, so there has to be another way to create the other 22 layerKind . How can this not be common knowledge?

JJMack‌ I want to retain the layer's adjustment state, without rasterization. I wanted to remove the mask simply because I find it distracting and usually end up deleting it anyway. A solid fill layer is different than a normal layer filled with a color in that when the canvas is resized, the color still fully covers it. Also to prevent a normal layer from being painted on it has to be locked, but then it's difficult to change the color. A fill layer allows you to change the color easily and often without risk of accidentally painting artifacts.

@Chuck Uebele  you are correct, that would work but for some reason I have to understand it, not just make it work. e.g. for add() as above.

Translate
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 ,
Jul 05, 2015 Jul 05, 2015

I totally understand! I'm the same way. I want to know how things work, so I can better use them. Finding documentation on this stuff is difficult at best. The DOM information has a bit more documentation than the AM code. A while ago I was trying to figure out how to modify some AM code. I asked Jeff Tranberry about it, and he replied, "It's a dark art."

Unfortunately, I think AM code is the only way to create a solid fill layer, and it is the only way to do a lot of PS operations:

Translate
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 ,
Jul 05, 2015 Jul 05, 2015

I think your right. If you try to set layer kind to something like solidfill you will get and error message you can only set LayerKind to NORMAL or TEXT

newLayer = app.activeDocument.artLayers.add();

newLayer.kind = LayerKind.SOLIDFILL;

JJMack
Translate
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 ,
Feb 29, 2024 Feb 29, 2024

Is it possible to distinguish between a solidfill filter and a rectangular shape?
I try the LayerKind property without luck, both say is a LayerKind.SOLIDFILL

Translate
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 ,
Feb 29, 2024 Feb 29, 2024

The only thing I get is that layer property grouped is false in case of shapes, and true in case of colorfill (also other kind of smart filter layers like levels etc.)... but I'm not sure

Translate
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 ,
Feb 29, 2024 Feb 29, 2024

I'm wrong grouped is anothe thing... 😕 I don't know who to distinguish shapes and solidcolor layer filters....

Translate
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 29, 2024 Feb 29, 2024
LATEST
Translate
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