Copy link to clipboard
Copied
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.
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() }
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)
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
Thank you, this worked perfectly.
Copy link to clipboard
Copied
How can i use it please menson?
Copy link to clipboard
Copied
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