How can I set the colour of a SOLIDFILL layer?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

I have a file that has several layers, all of which are of type SOLIDFILL (they are all vector masked items). I need to first get the colour of SOLIDFILL layer 1 and apply it to SOLIDFILL layers 2-5.

There is only one entry in the javascript manual for SOLIDFILL and it is under the LayerKind description...nothing else. I can't make it work by assigning a SolidColor object, because I don't know what to assign the SolidColor object *to.*

Has anyone figured this out?

...Mike
Patrick

How can I set the colour of a SOLIDFILL layer?

Post by Patrick »

I looked and I had no luck either, there does not appear to be a (obvious) way to change the color on these objects. If you need to change the color, I would try just deleting the existing object and creating a new one of the desired color in its place. Not ideal but the only thing I could think of.

Code: Select all// equivelant of Layer -> New Fill Layer -> Solid Color
function NewFillLayer(r,g,b) {
   var id133 = charIDToTypeID( "Mk  " );
       var desc30 = new ActionDescriptor();
       var id134 = charIDToTypeID( "null" );
           var ref13 = new ActionReference();
           var id135 = stringIDToTypeID( "contentLayer" );
           ref13.putClass( id135 );
       desc30.putReference( id134, ref13 );
       var id136 = charIDToTypeID( "Usng" );
           var desc31 = new ActionDescriptor();
           var id137 = charIDToTypeID( "Type" );
               var desc32 = new ActionDescriptor();
               var id138 = charIDToTypeID( "Clr " );
                   var desc33 = new ActionDescriptor();
                   var id139 = charIDToTypeID( "Rd  " );
                   desc33.putDouble( id139, r );
                   var id140 = charIDToTypeID( "Grn " );
                   desc33.putDouble( id140, g );
                   var id141 = charIDToTypeID( "Bl  " );
                   desc33.putDouble( id141, b );
               var id142 = charIDToTypeID( "RGBC" );
               desc32.putObject( id138, id142, desc33 );
           var id143 = stringIDToTypeID( "solidColorLayer" );
           desc31.putObject( id137, id143, desc32 );
       var id144 = stringIDToTypeID( "contentLayer" );
       desc30.putObject( id136, id144, desc31 );
   executeAction( id133, desc30, DialogModes.NO );
}

NewFillLayer(0,0,255);   // make a blue fill layer

Patrick
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

This is pretty close.

Code: Select all//@include "xlib/stdlib.js"

function getAdjustmentLayerColor(doc, layer) {
   var desc = Stdlib.getLayerDescriptor(doc, layer);

   // was  var adjs = desc.getList(desc, cTID('Adjs'));
   // EDIT: fixed -x
   var adjs = desc.getList(cTID('Adjs'));

   var clrDesc = adjs.getObjectValue(0);
   var color= clrDesc.getObjectValue(cTID('Clr '));

   var red = color.getDouble(cTID('Rd  '));
   var green = color.getDouble(cTID('Grn '));
   var blue = color.getDouble(cTID('Bl  '));

   return Stdlib.createRGBColor(red, green, blue);
};

This is transcribed from a jsh log, but this is basically how adjustment layers work. There is an 'Adjs' list which _usually_ has one Adjustment object, in this case a solidColorLayer. Inside of that is the color descriptors.

-X
miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

Thanks guys. I can't just delete the layer because it has a mask that I don't want to lose.

xbytor can I use a similar routine to assign a colour to a layer of this type as well? and what is xlib/stdlib.js?

...Mike
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

Code: Select allcTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

function changeSolidFillLayerColor(color) {
    var rgb = color.rgb;

    var desc37 = new ActionDescriptor();
        var ref19 = new ActionReference();
        ref19.putEnumerated( sTID('contentLayer'), cTID('Ordn'), cTID('Trgt') );
    desc37.putReference( cTID('null'), ref19 );
        var desc38 = new ActionDescriptor();
            var desc39 = new ActionDescriptor();
            desc39.putDouble( cTID('Rd  '), rbg.red );
            desc39.putDouble( cTID('Grn '), rgb.green );
            desc39.putDouble( cTID('Bl  '), rgb.blue );
        desc38.putObject( cTID('Clr '), cTID('RGBC'), desc39 );
    desc37.putObject( cTID('T   '), sTID('solidColorLayer'), desc38 );
    executeAction( cTID('setd'), desc37, DialogModes.NO );
};

// example
//changeSolidFillLayerColor(app.foregroundColor);



This will modify the color of an existing solid fill color layer.

-X
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

Code: Select alland what is xlib/stdlib.js?

It's part of a toolkit that I've developed, with some participation of others on this site:
bb/viewforum.php?f=25

There is a lot reusable code in there. I find it difficult to write anything of an complexity without using code from there.

If you just want the code, here's the link:
http://ps-scripts.cvs.sourceforge.net/* ... /stdlib.js ... /stdlib.js

and here are the docs:
http://ps-scripts.cvs.sourceforge.net/p ... f?view=log ... f?view=log


-X
miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

Thanks X. I notice that the doc has no licensing information. What license is it released under?

...Mike
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

Every script should have:

Code: Select all// Copyright: (c)2007, xbytor
// License: http://creativecommons.org/licenses/LGPL/2.1


You can follow that link for more details.

There is also a COPYRIGHT file at the toplevel directory that contains more information as well as notes on code that I've brought in that is covered by other licenses.

But, the basic rule is, do whatever you want with the code, including selling it. Just don't say you wrote it and do keep the copyright/license info in the scripts.

-X
miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

getAdjustmentLayerColor is throwing an error in PS CS3.

Error 1242: Illegal Arguement - arguement 1 - Numeric value expected
var adjs = desc.getList(desc, cTID('Adjs'));

This is the problem with code I don't understand...i can't debug it Here is what I have:


Code: Select all//@include "stdlib.js"

docRef = activeDocument;
layerRef = docRef.layers["primary"];

var colorOBJ = new RGBColor();

colorOBJ = getAdjustmentLayerColor(docRef, layerRef);

alert(colorOBJ.blue);

function getAdjustmentLayerColor(doc, layer) {
   var desc = Stdlib.getLayerDescriptor(doc, layer);
   var adjs = desc.getList(desc, cTID('Adjs'));
   var clrDesc = adjs.getObjectValue(0);
   var color= clrDesc.getObjectValue(cTID('Clr '));

   var red = color.getDouble(cTID('Rd  '));
   var green = color.getDouble(cTID('Grn '));
   var blue = color.getDouble(cTID('Bl  '));

   return Stdlib.createRGBColor(red, green, blue);
}
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

Code: Select all   var adjs = desc.getList(desc, cTID('Adjs'));

should be:

Code: Select all   var adjs = desc.getList(cTID('Adjs'));

just like the docs say

-X