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

Photoshop Javascript change layer color

Community Beginner ,
May 15, 2017 May 15, 2017

Copy link to clipboard

Copied

Hello I am writing scripts to automate Adobe Photoshop process. I am using JavaScript as my scripting language.
I've never used JavaScript in photoshop environment and i was wondering if someone could offer me some advice.
Here is a high level overview of what i am trying to accomplish.
  1) Get a data set from a JSON file
  2) Loop through the JSON file and pull data which will then be passed into the image layers
  3) Apply patterns and colors to each layer

4) Save file

The first 2 steps are relatively simple (basic javascript patterns) How ever where i start to run into trouble is when i am actually trying to manipulate the image in the photoshop.
How would I change the color of a layer ?
Here is my code snippet that is NOT working

          function changeColor(){

            var class2hex = app.activeDocument.artLayers.getByName("CLASS2HEX");

             alert(class2hex.kind) // LayerKind.SOLIDFLL
              var Color = new SolidColor();
             Color.rgb.hexValue = 'a5142f'';
             
              // HOW DO I APPLY THE COLOR TO THE LAYER?
               // ALSO how would i change the layer pattern in a similar fashion ?

Thank you!

TOPICS
Actions and scripting

Views

3.7K

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
Contributor ,
May 16, 2017 May 16, 2017

Copy link to clipboard

Copied

LATEST

//

var docRef = app.activeDocument;

//displayDialogs = DialogModes.ALL

// define your fill color

var color = new SolidColor();

color.rgb["hexValue"] = "7f7f7f";

var  monCalc = app.activeDocument.artLayers.getByName("CLASS2HEX");

docRef.activeLayer =  monCalc ;

for ( j=0;j<docRef.layers.length;j++) //masquer tous les calques

         {

            docRef.layers.visible=false;

         } 

monCalc.visible=true;

var moncalc2 = monCalc.duplicate();//conserver le texte original

pixeliser();//Transformer le calque texte en calque simple

//Rogner

docRef.trim(TrimType.TOPLEFT, true, true, true, true);

//var class2hex = app.activeDocument.artLayers.getByName("CLASS2HEX");

//             alert(class2hex.kind) // LayerKind.SOLIDFLL

for ( j=0;j<docRef.layers.length;j++) //Demasquer tous les calques

         {

            docRef.layers.visible=true;

         } 

moncalc2.visible=true;

// perform select all & fill the document

// monCalc

docRef.selection.selectAll();

docRef.selection.fill(color);

docRef.selection.deselect();

function pixeliser()

{

var idMk = charIDToTypeID( "Mk  " );

    var desc165 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref14 = new ActionReference();

        var idSnpS = charIDToTypeID( "SnpS" );

        ref14.putClass( idSnpS );

    desc165.putReference( idnull, ref14 );

    var idFrom = charIDToTypeID( "From" );

        var ref15 = new ActionReference();

        var idHstS = charIDToTypeID( "HstS" );

        var idCrnH = charIDToTypeID( "CrnH" );

        ref15.putProperty( idHstS, idCrnH );

    desc165.putReference( idFrom, ref15 );

executeAction( idMk, desc165, DialogModes.NO );

}

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