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

Photoshop JS Script that displays RGB values on text layer.

New Here ,
May 08, 2017 May 08, 2017

How would I write a JS that changes the text layer to display the current RGB value of a different layer and updates when that layer color is changed?

So if I were to change the fill color of a shape object it the script read that RGB value and display it as a on the text layer.

1.PNG

This is what I have so far. It selects the layer, I can change the color but now I need it to also display the RGB values on the separate text layer.

dlg.color1Btn.onClick = function(){

        app.activeDocument.activeLayer = app.activeDocument.layerSets.getByName("Colors").artLayers.getByName("1");

        app.activeDocument.selection.selectAll();

        getColor();

        app.activeDocument.selection.fill(foregroundColor , undefined, undefined, true);

        app.activeDocument.selection.deselect();

        app.refresh();

        }

function getColor(){  showColorPicker()  }

TOPICS
Actions and scripting
2.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 , May 08, 2017 May 08, 2017

You can get the target the layer associated with the color of the box and change the text value like the below script. Of course you can put this all in a function, and format the output to show three digits by changing it to a string and doing some other code.

#target photoshop

var doc = activeDocument;

var txtLayer = doc.layers.getByName('box 1');

doc.activeLayer = txtLayer

txtLayer.textItem.contents = 'Red: '+  parseInt( foregroundColor.rgb.red) + '\rGreen: ' + parseInt(foregroundColor.rgb.green)

...
Translate
Adobe
Community Expert ,
May 08, 2017 May 08, 2017

You can get the target the layer associated with the color of the box and change the text value like the below script. Of course you can put this all in a function, and format the output to show three digits by changing it to a string and doing some other code.

#target photoshop

var doc = activeDocument;

var txtLayer = doc.layers.getByName('box 1');

doc.activeLayer = txtLayer

txtLayer.textItem.contents = 'Red: '+  parseInt( foregroundColor.rgb.red) + '\rGreen: ' + parseInt(foregroundColor.rgb.green) +  '\rBlue: ' + parseInt(foregroundColor.rgb.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
New Here ,
May 08, 2017 May 08, 2017

Thank you, this worked perfectly.

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 ,
Dec 18, 2023 Dec 18, 2023

How can i use it please menson?

 

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 ,
Dec 19, 2023 Dec 19, 2023
LATEST
quote

How can i use it please menson?

 


By @Familier with Photoshop


Info on saving and executing scripts here:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

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