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

Community Beginner ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

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,

 

TOPICS
Actions and scripting, How to, Mac

Views

381

Likes

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

correct answers 2 Correct Answers

Enthusiast , Mar 14, 2021 Mar 14, 2021
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);

Likes

Translate

Translate
Adobe Community Professional , Mar 14, 2021 Mar 14, 2021
txt = (aD = activeDocument).activeLayer.textItem.contents; (solidcolor = new SolidColor).rgb.hexValue = txt; (aD.artLayers.add()).name = 'swatch' aD.selection.fill(solidcolor)

Likes

Translate

Translate
Adobe Community Professional ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

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)?

Likes

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
Community Beginner ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

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):

 

Screen Shot 2021-03-14 at 10.03.56 AM.png

Screen Shot 2021-03-14 at 10.10.49 AM.png

 

- Theorteical end result:

 

Screen Shot 2021-03-14 at 10.04.00 AM.png Screen Shot 2021-03-14 at 10.03.52 AM.png

 

 

Likes

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
Community Beginner ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

Whoops, .psd files. I doubt that matters though

Likes

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
Enthusiast ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

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);

Likes

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 Community Professional ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

 

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

 

Likes

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
Enthusiast ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

LATEST

damn! it was obvious 🙂

Likes

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
Community Beginner ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

I am so happy right now, you have no idea. Thank you!!! I have awarded yours as the correct answer as it was the first one in!

Likes

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 Community Professional ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

I'm glad you have the answers you need, I thought that the text was coloured with the hex fill colour, so I was looking at geting the colour property from the text object, now that I can see images that would not have worked as I misunderstood your previous posts.

Likes

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 Community Professional ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

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?

Likes

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
Community Beginner ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

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.

Likes

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