-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathChannel Labels.jsx
60 lines (57 loc) · 2.67 KB
/
Channel Labels.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
// set this to space the labels
var horizontalOffest = new UnitValue(10,'pt');
var doc = app.activeDocument;
var currentLayer = doc.activeLayer;
var textLayer = doc.artLayers.add();
textLayer.kind = LayerKind.TEXT;
// font requires the postscript name of the font
textLayer.font = "ArialMT-Bold";
textLayer.textItem.size = new UnitValue(15,'pt');
textLayer.textItem.fauxBold = true;
textLayer.textItem.justification = Justification.RIGHT;
textLayer.textItem.capitalization = TextCase.ALLCAPS;
// set the position for the text. this sets to top right corner of the channel
// here it is set so the text baseline ends 40pts from the right edge, 15pts down
textLayer.textItem.position = [new UnitValue(doc.width.as('pt')-30,'pt'),new UnitValue(25,'pt')];
textLayer.textItem.contents = 'label';// temp label string
for(var channelIndex = 0; channelIndex<doc.channels.length; channelIndex++){
var newTextLayer = textLayer.duplicate();
doc.activeLayer = newTextLayer;
newTextLayer.textItem.contents = doc.channels[channelIndex].name;
newTextLayer.textItem.position = [new UnitValue(doc.width.as('pt')-(30+(horizontalOffest.as('pt')*channelIndex)),'pt'),new UnitValue(25,'pt')];
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.activeChannels = [doc.channels[channelIndex]];
doc.selection.fill(black);
doc.selection.deselect();
selectComponentChannel();
newTextLayer.remove();
}
textLayer.remove();
function loadActiveLayerTransparencyToSelection() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
desc.putReference( charIDToTypeID('null'), ref );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
desc.putReference( charIDToTypeID('T '), ref );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
function selectComponentChannel() {
try{
var map = {}
map[DocumentMode.GRAYSCALE] = charIDToTypeID('Blck');
map[DocumentMode.RGB] = charIDToTypeID('RGB ');
map[DocumentMode.CMYK] = charIDToTypeID('CMYK');
map[DocumentMode.LAB] = charIDToTypeID('Lab ');
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), map[app.activeDocument.mode] );
desc.putReference( charIDToTypeID('null'), ref );
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}catch(e){}
};