I work for a screen printing company and I'm trying to speed up my workflow. I saw an article about PS Scripting and I thought it would be a good idea to try.
I'll quickly describe my routine:
Once the design is done I have to split it into every color it have using Spot Color Channels and apply leveling, curves, blend modes, etc... After that I've to apply registration marks and color guides and here is where I want the automatization because it is time consuming.
The difficulty I'm facing is my file is Multichannel type and and because it doesn't have any color space (RGB, CMYK, Grayscale or LAB) I cant add any kind of new layer on it and I want to create a text element with the color name on the upper right corner of every channel/color it have.
I've found this piece of code:
Code: Select all
// 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){}
};
PS: English isn't my main language, i'm using google translator a lil bit.