Artboards

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

d3mac123
Posts: 1
Joined: Thu Jan 01, 1970 12:00 am

Artboards

Post by d3mac123 »

Is there any documentation on how to work with Artboards? I've noticed they can be listed as a group layer:

Code: Select all


docRef.layers.length
the example above will return 2 if 2 artboards are found in a PSD file.

However, trying to extract the color of a layer inside the artboard, for example, with the code below will generate an error:

Code: Select all


function getFillColor(){
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
var ref1= executeActionGet( ref );
var list = ref1.getList( charIDToTypeID( "Adjs" ) ) ;
var solidColorLayer = list.getObjectValue(0);
var color = solidColorLayer.getObjectValue(charIDToTypeID('Clr '));
var fillcolor = new SolidColor;
fillcolor.rgb.red = color.getDouble(charIDToTypeID('Rd '));
fillcolor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
fillcolor.rgb.blue = color.getDouble(charIDToTypeID('Bl '));
return fillcolor.rgb.hexValue;
};
The error happens in this line:

Code: Select all


var ref1= executeActionGet( ref );
Calling the same function in a "regular/non artboard" file, returns the right color of the layer.

Any ideas?
Thanks,
Alex
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Artboards

Post by Kukurykus »

I'm not sure I undestood you, so correct me if I'm wrong:

You can check color of activeDocument.activeLayer.kind == LayerKind.SOLIDFILL by this function, but you want to check a color of activeDocument.activeLayer.kind == LayerKind.NORMAL ?

Well if it's what you want then layer must be filled by only one colour (I mean it can't contain 2 or more colours as it'd differ it from Color Fill layer). Otherwise you couldn't check the colour of layer as that would be "multi-colour", and then you could check for example average colour or most pixels colour etc

A code I wrote you can use somehow when you're sure normal layer has only one colour, however it won't do anything if there are more colours, or it's background layer (what if I had more time now I could do working in this script as well). Tell me if it is what you meant?

Below you find what following script do:

- check is activeLayer a NORMAL layer
- check does this layer contain only one colour
- if so then save current historyState
- check histogram on all RGB channels
- set back history and say HEX value colour

Code: Select all

if ((aL = (aD = activeDocument).activeLayer).kind == 'LayerKind.NORMAL') {
bol = false, col = new SolidColor, aHS = aD.activeHistoryState
aL.duplicate(tL = aD.layers[0], ElementPlacement.PLACEBEFORE), aD.activeLayer = tL
if (String(aD.histogram).match(/[1-9](\d+)?/g).length == 1) {
for(i = 0, arr = ['red', 'green', 'blue']; i < arr.length; i++) {
eval('col.rgb.' + arr[i] + ' = String(aD.channels[i].histogram).match(/[0,]*(?=[1-9])/)[0].length / 2')
bol = true
}
}
aD.activeHistoryState = aHS
if (bol) alert(col.rgb.hexValue)
}

Ps. I haven't much time yet to test it and I didn't wrote everything I wanted but it should work with specified conditions.
Attachments
Color Check.zip
(652 Bytes) Downloaded 492 times