Multichannel file and text element on channel layer !HELP!

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

fernan2.jr
Posts: 2
Joined: Thu Apr 21, 2022 9:16 pm

Multichannel file and text element on channel layer !HELP!

Post by fernan2.jr »

Hi, Guys... A fresh newbie here, please bear with me.
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){}

};
Is there any way to adapt it to my needs??

PS: English isn't my main language, i'm using google translator a lil bit.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Multichannel file and text element on channel layer !HELP!

Post by Kukurykus »

'Rar' and attach 2 psd's, one simple example you want to process, a second the result of your manual work (so that one, the script has to create).
fernan2.jr
Posts: 2
Joined: Thu Apr 21, 2022 9:16 pm

Re: Multichannel file and text element on channel layer !HELP!

Post by fernan2.jr »

Kukurykus wrote: Fri Apr 22, 2022 5:33 am 'Rar' and attach 2 psd's, one simple example you want to process, a second the result of your manual work (so that one, the script has to create).
I can't attach it here, it says the file is too large.

https://we.tl/t-YUVD7P33Vx

Hope this could help!
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Multichannel file and text element on channel layer !HELP!

Post by Kukurykus »

I sent private message to you...