Copy link to clipboard
Copied
I am a screen printer and I print my separations from Photoshop. I routinely work with multi channel files or RGB files with additional spot color channels. I have created actions to place my registration marks, re-size images, etc to get ready to print but I manually have to create the text labels for each screen if they are missing from the original artwork.
The files I work with have channels named as "Base White, Red, Green, 284 Blue" etc indicating the ink color. What i would like to be able to do is create a script that would copy the text from the channel name and insert it into a separate or each/all channels near the top of the file so that when I print each positive it has a corresponding label for ink color.
I am not sure if this is even possible, and I am limited on my knowledge when it comes to actions and no experience with scripts and have pretty much got lucky in the past getting the actions to do what I want without unnecessary steps.
On my registration target action it creates a new channel with each individual reg mark then combines them into one separate channel in which I just copy the contents and select all the ink channels and fill with black to make them appear, i'm happy with the steps it takes as it isn't too much trouble and if this could do the same with labels I would be happy with that.
Thanks in advance!
Something like this?
...// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
// set this to space the labels
var horizontalOffest = new UnitValue(20,'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";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// s
Copy link to clipboard
Copied
Sorry, but I am not clear what you want. Do you want to start with a single document that may have extra channels and label each channel on the channel itself? i.e the red channel has the chars 'red' in only that channel.
Is the label placed in the slug? I think we would need to know where you want the label placed, font, size, etc. I assume if it is in the slug the color should be black.
But If I did understand your request it is possible with a script.
Copy link to clipboard
Copied
I'm not sure I understand what the term "slug" refers to. I have attached an image of a single channel selected with a label at the top as "Black"
Basically I am wanting to take the text from the channel name and add text in a standard block font (maybe Arial or such) at .125" (9pt) and insert it into the channel between the registration marks, if spacing cannot be done, I can do that manually.
I don't really know what my options are on making this happen and how advanced it can be, so I am trying to figure that out.
Thanks again for the reply.
Copy link to clipboard
Copied
This will put the name of the channel in the top right corner of each channel. I tried to comment where and how you can modify it to meet your needs but if you have any questions let me know. It should work with Grayscale, RGB, CMYK, or Lab mode and with any ruler unit execpt percent.
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
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";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// 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')-50,'pt'),new UnitValue(15,'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;
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){}
};
Copy link to clipboard
Copied
Thank you very much. I have played with this and believe it will work pretty good. I do have one question though, is it possible to make the script place the next label so many points away from the previous label? I can do this manually but it seems quite a bit is possible using scripting so I thought I would ask.
Thanks!
Copy link to clipboard
Copied
Something like this?
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
// set this to space the labels
var horizontalOffest = new UnitValue(20,'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";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// 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')-50,'pt'),new UnitValue(15,'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')-(50+(horizontalOffest.as('pt')*channelIndex)),'pt'),new UnitValue(15,'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){}
};
Copy link to clipboard
Copied
I think we are on the right track, this is what I ended up with after running the below (I made a few changes to make text bold and in all caps)
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
// set this to space the labels
var horizontalOffest = new UnitValue(20,'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(0.125,'in');
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')-50,'pt'),new UnitValue(15,'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')-(50+(horizontalOffest.as('pt')*channelIndex)),'pt'),new UnitValue(15,'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){}
};
Copy link to clipboard
Copied
I think we are on the right track...
Note sure if that means you are happy or if something else needs to be done.
Copy link to clipboard
Copied
Actually, this works great. It doesn't matter if they overlap. Thank you very much for doing this for me! I have a couple other ideas I'd like to try to do also if you have the time. I will send you a pm on those.
Copy link to clipboard
Copied
This script combines adding the marks and labels in one script.
// the file used as registration mark
var markFile = new File('~/desktop/reg_mark.eps');
var doc = app.activeDocument;
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
var currentLayer = doc.activeLayer;
var textLayer = doc.artLayers.add();
textLayer.kind = LayerKind.TEXT;
// font requires the postscript name of the font
textLayer.font = "ArialMT";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// 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')-50,'pt'),new UnitValue(15,'pt')];
textLayer.textItem.contents = 'label';// temp label string
makeMarksLayer();
var marksLayer = doc.activeLayer;
for(var channelIndex = 0; channelIndex<doc.channels.length; channelIndex++){
var newTextLayer = textLayer.duplicate();
doc.activeLayer = newTextLayer;
newTextLayer.textItem.contents = doc.channels[channelIndex].name;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.activeChannels = [doc.channels[channelIndex]];
doc.selection.fill(black);
doc.selection.deselect();
doc.activeLayer = marksLayer;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.selection.fill(black);
doc.selection.deselect();
selectComponentChannel();
newTextLayer.remove();
}
textLayer.remove();
marksLayer.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){}
};
function makeMarksLayer(){
var markLayer = doc.artLayers.add();
executeAction( stringIDToTypeID( "newPlacedLayer" ), undefined, DialogModes.NO );
executeAction( stringIDToTypeID( "placedLayerEditContents" ), new ActionDescriptor(), DialogModes.NO );
var smartObjectDoc = app.activeDocument;
placeEPS(markFile);
var placedLayer = smartObjectDoc.activeLayer;
smartObjectDoc.selection.selectAll();
alignTopLeft();
placedLayer.duplicate();
alignTopCenter();
placedLayer.duplicate();
alignTopRight();
placedLayer.duplicate();
alignBottomLeft();
placedLayer.duplicate();
alignBottomCenter();
placedLayer.duplicate();
alignBottomRight();
smartObjectDoc.close(SaveOptions.SAVECHANGES);
};
function placeEPS(file) {
var desc = new ActionDescriptor();
var desc1 = new ActionDescriptor();
desc1.putEnumerated( charIDToTypeID('fsel'), stringIDToTypeID('pdfSelection'), stringIDToTypeID('page') );
desc1.putInteger( charIDToTypeID('PgNm'), 1 );
desc1.putEnumerated( charIDToTypeID('Crop'), stringIDToTypeID('cropTo'), stringIDToTypeID('artBox') );
desc.putObject( charIDToTypeID('As '), charIDToTypeID('PDFG'), desc1 );
desc.putPath( charIDToTypeID('null'), new File( file ) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), 100.000000 );
desc.putUnitDouble( charIDToTypeID('Hght'), charIDToTypeID('#Prc'), 100.000000 );
desc.putBoolean( charIDToTypeID('Lnkd'), true );
desc.putBoolean( charIDToTypeID('AntA'), true );
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
};
function align(type){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Lnkd" ));
desc.putReference( charIDToTypeID( "null" ), ref);
desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ), charIDToTypeID( type ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );;
};
function alignCenter(){
align("AdCH");
align("AdCV");
};
function alignTopLeft(){
align("AdTp");
align("AdLf");
};
function alignTopCenter(){
align("AdTp");
align("AdCH");
};
function alignTopRight(){
align("AdTp");
align("AdRg");
};
function alignBottomLeft(){
align("AdBt");
align("AdLf");
};
function alignBottomCenter(){
align("AdBt");
align("AdCH");
};
function alignBottomRight(){
align("AdBt");
align("AdRg");
};
Copy link to clipboard
Copied
This works well, I edited out the bottom left and right marks, but it appears that it only places the marks on the Red, Green, & Blue channels.
// the file used as registration mark
var markFile = new File('~/desktop/reg_mark.eps');
var doc = app.activeDocument;
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
var currentLayer = doc.activeLayer;
var textLayer = doc.artLayers.add();
textLayer.kind = LayerKind.TEXT;
// font requires the postscript name of the font
textLayer.font = "ArialMT";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// 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')-50,'pt'),new UnitValue(15,'pt')];
textLayer.textItem.contents = 'label';// temp label string
makeMarksLayer();
var marksLayer = doc.activeLayer;
for(var channelIndex = 0; channelIndex<doc.channels.length; channelIndex++){
var newTextLayer = textLayer.duplicate();
doc.activeLayer = newTextLayer;
newTextLayer.textItem.contents = doc.channels[channelIndex].name;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.activeChannels = [doc.channels[channelIndex]];
doc.selection.fill(black);
doc.selection.deselect();
doc.activeLayer = marksLayer;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.selection.fill(black);
doc.selection.deselect();
selectComponentChannel();
newTextLayer.remove();
}
textLayer.remove();
marksLayer.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){}
};
function makeMarksLayer(){
var markLayer = doc.artLayers.add();
executeAction( stringIDToTypeID( "newPlacedLayer" ), undefined, DialogModes.NO );
executeAction( stringIDToTypeID( "placedLayerEditContents" ), new ActionDescriptor(), DialogModes.NO );
var smartObjectDoc = app.activeDocument;
placeEPS(markFile);
var placedLayer = smartObjectDoc.activeLayer;
smartObjectDoc.selection.selectAll();
alignTopLeft();
placedLayer.duplicate();
alignTopCenter();
placedLayer.duplicate();
alignTopRight();
placedLayer.duplicate();
alignBottomCenter();
smartObjectDoc.close(SaveOptions.SAVECHANGES);
};
function placeEPS(file) {
var desc = new ActionDescriptor();
var desc1 = new ActionDescriptor();
desc1.putEnumerated( charIDToTypeID('fsel'), stringIDToTypeID('pdfSelection'), stringIDToTypeID('page') );
desc1.putInteger( charIDToTypeID('PgNm'), 1 );
desc1.putEnumerated( charIDToTypeID('Crop'), stringIDToTypeID('cropTo'), stringIDToTypeID('artBox') );
desc.putObject( charIDToTypeID('As '), charIDToTypeID('PDFG'), desc1 );
desc.putPath( charIDToTypeID('null'), new File( file ) );
desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), 100.000000 );
desc.putUnitDouble( charIDToTypeID('Hght'), charIDToTypeID('#Prc'), 100.000000 );
desc.putBoolean( charIDToTypeID('Lnkd'), true );
desc.putBoolean( charIDToTypeID('AntA'), true );
executeAction( charIDToTypeID('Plc '), desc, DialogModes.NO );
};
function align(type){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Lnkd" ));
desc.putReference( charIDToTypeID( "null" ), ref);
desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ), charIDToTypeID( type ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );;
};
function alignCenter(){
align("AdCH");
align("AdCV");
};
function alignTopLeft(){
align("AdTp");
align("AdLf");
};
function alignTopCenter(){
align("AdTp");
align("AdCH");
};
function alignTopRight(){
align("AdTp");
align("AdRg");
};
function alignBottomCenter(){
align("AdBt");
align("AdCH");
};
Copy link to clipboard
Copied
Oops, replace the for loop with this one.
for(var channelIndex = 0; channelIndex<doc.channels.length; channelIndex++){
var newTextLayer = textLayer.duplicate();
doc.activeLayer = newTextLayer;
newTextLayer.textItem.contents = doc.channels[channelIndex].name;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.activeChannels = [doc.channels[channelIndex]];
doc.selection.fill(black);
doc.selection.deselect();
doc.activeLayer = marksLayer;
loadActiveLayerTransparencyToSelection();
doc.activeLayer = currentLayer;
doc.activeChannels = [doc.channels[channelIndex]];
doc.selection.fill(black);
doc.selection.deselect();
selectComponentChannel();
newTextLayer.remove();
}
Copy link to clipboard
Copied
Thank you sir! This works great, and saves me probably 10 minutes per job when labels and marks are missing.
Copy link to clipboard
Copied
I know this is an older post, but I'll try here before posting again. The below script works as expected (putting the channel name into the channel's pixel data) with a few requests
First, setting the font doesn't work for me. It is a postscript name and I have checked that the font is installed.
Second, is there a way for it to skip the default rgb or cmyk channels?
Last, can it skip a custom channel name, for instance, if the channel is named "PLACEHOLDER" it will skip the process as well.
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
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(9,'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')-8,'pt'),new UnitValue(10,'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;
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){}
};
Copy link to clipboard
Copied
How would I do the same thing but a script to add the FileName to all Channels? Many thanks!