Skip to main content
Participant
March 13, 2021
Answered

Photoshop Script Help (hex value in text layer to fill layer)

  • March 13, 2021
  • 2 replies
  • 2221 views

I keep trying this from different angles but I am clearly not succeeding. 

I have thousands of hex codes in a CSV that I inserted as a variable into a text layer into respective tiffs. Ie, CSV says "000000", a text layer now reads "000000" in its own unique tiff.

 

I am wondering how on earth to copy the text from that layer (hex value), and fill a new layer on top with that colour, then save the file as a jpg. I imagine it's a script that would be added into an action? 

I originally started with actions, but found that I couldn't actually get the hex code copied onto the clipboard to work, it just kept using the hex values from my tests (and ended up with about 100 pink squares before I stopped it).


I tried looking into writing my own script, but that didn't work, as I do not have very much JS experience. 

I have tried to look into the community boards but they are slight differences that I do not know how to edit to make work for what I need.

 

I have looked into the VariableImporter.jsx from Vasily Hall, was sure to set up the file with notes in Illustrator, but clearly didn't do it correctly as I wouldn't be writing this, hah.

 

Looking for tips and assistance,

 

This topic has been closed for replies.
Correct answer Kukurykus
t=(ad = activeDocument).activeLayer.textItem.contents;
(c = new SolidColor).rgb.red = parseInt(t.substr(0,2),16);
c.rgb.green =  parseInt(t.substr(2,2),16);
c.rgb.blue = parseInt(t.substr(-2),16);
(ad.artLayers.add()).name ='swatch';
ad.selection.fill(c);

 

txt = (aD = activeDocument).activeLayer.textItem.contents;
(solidcolor = new SolidColor).rgb.hexValue = txt;
(aD.artLayers.add()).name = 'swatch'
aD.selection.fill(solidcolor)

 

2 replies

Chuck Uebele
Community Expert
Community Expert
March 14, 2021

So do you want to automatically create all the files based on the CVS? You could have a base file formatted with the text and a solid color fill layer, then have a script change the text value and the fill color. Or you could just create a new file each time. How is the CVS formatted: all values in a row or a column?

Participant
March 14, 2021

More than one way to skin a cat I guess hah.

 

The data lives in a google sheet, that I've exported the relevant columns as a CSV to work locally. It does not need to be data that is pulled constantly, just a one time use. It has 2 columns with maybe 2k rows of values?

 

Using actions and variables, I created all the artwork, named as needed, in the correct size with the hex value in it as I couldn't figure another way without any scripting knowledge.  The end result will be a jpg, so there is no need for the text layer in the end, I just didn't know how to pull it.

Stephen Marsh
Community Expert
Community Expert
March 14, 2021

How many text layers per file? Only one?

 

Is the source text layer always in a consistent position in the layer stack, i.e. at the top?

 

Where/what position will the new solid fill layer appear in the layer stack in relation to the source text layer?

 

Can you show a cropped screenshot of the layers panel from a few different files (with all layer sets fully expanded)?

Participant
March 14, 2021

There is only one text layer per file, and I have placed the text layer in the same spot for every layer.

 

New solid fill would be a new layer on top (making hex value irrelevant visually).

Please let me know if I can expand more:

-current tiff file with one text layer (pulled using variables following PiXimperfect's tutorial):

 

 

- Theorteical end result:

 

 

 

 

Participant
March 14, 2021

Whoops, .psd files. I doubt that matters though