0

First time posting after trying to figure out a solution that would save me time with a project I'm doing. I Have this idea of using a CSV document to generate colour patches needed for another program. being a designer I don't have much experience with scripts or programming except the basic java.

The program I want to make needs to do as follows : Collum 1 - Filename to save. Collum 3 - file identifier to save. Example of this is :

Name | id | Type

|dave | 1 | Default

Output would be Dave_Default.png

Next id need it to read the values of columns 4,5,6 as rgb values : Example :

Name | id | Type | R | G | B |

| dave | 1 | Default |187|112|0 |

then take those values and generate a 10 x 10-pixel block in that colour value. Save the 10x10px square as a .png with the file name as stated before then move on to the next one on the rows.

End result is : Dave_Default.png - Colour png swatch

I'm sure this is a lot to ask but any help would be amazing as it would save hours and hours of work manually inputting the RGB values into photoshop and exporting a png one at a time.

Thanks in advance.

1

Scripting is relatively simple in Photoshop and you can easily scrap bits of code from google. Obviously any proficiency in Javascript would save you a lot of time, so I'd recommend to spend an hour and take a course on basics of JS on any code learning web academy.

Next you'll need to read your csv: the first google link will show you how.

From this file you'll get a bunch of strings, say dave,1,Default,187,112,0, so you'll make an array of them first with string.split(','). This will give you an array [dave,1,Default,187,112,0] so you could access the color values as arr[3], arr[4] and arr[5]. Voilà — you have a bunch of data to work with.

Next for each data string you'll need to create a new document. Let's see what Photoshop Scripting Guide says about this: it seems like there's exactly what you need on page 104: documents (a collection of opened documents) has a method .add, so you can do documents.add(new UnitValue(10, 'px'),new UnitValue(10, 'px'));

Now you'll want to fill it with color. First you need to set a color to fill with, there's a SolidColor object in Photoshop to contain color information and .fill() method of selection object to fill a selection with color. So you first define the color, select all, fill with color. And you can use the values you have already for this:

var newColor = new SolidColor;
newColor.rgb.red = arr[3];
newColor.rgb.green = arr[4];
newColor.rgb.blue = arr[5];
app.activeDocument.selection.selectAll();
app.activeDocument.selection.fill(newColor);
app.activeDocument.selection.deselect();

Almost done, you only need to save the file. Once again, google to the rescue.

And that's it.

  • You Legend ! Thanks my google fu was not so strong today ! – Carbon Caffeine Jul 19 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.