Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Paste content in alpha channel into layers (ScreenPrint)

Contributor ,
Jan 10, 2023 Jan 10, 2023

Hello community, hope eveybody is doing great!

 

Can anybody help me with my code? I am trying to copy all the info in my alpha channels (spot colors maybe?) to create layer with it's name, I found this one:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/convert-all-alpha-channels-into-layer...

 

and works good! but it creates things that... I don't know what are they like the ones I point in this screen shot:

 

AntonioPachecoHN_0-1673363203638.png

The image is in "negative" if I explain myself good, the layers seems to be masked and I need it like a normal layer, I don't know what is that channel I am point which gets the name of the layer I choose, idk.... Here is a code I've been working but I honestly surrender, sorry about the spanish:

 

var doc = app.activeDocument;
var channelList = [];
if (activeDocument.mode == DocumentMode.RGB) {
alert("the doc is RGB");
for (var i = 2; i < doc.channels.length; i++) {
alert("valor de i es " + i + " conteo en la lista es " + channelList.length);
alert(doc.channels[i].name);
channelList.push(doc.channels[i].name);
alert("conteo en la lista es " + channelList.length);
alert("ahora se va a seleciconar el canal " + channelList[i-2]);
doc.activeChannels = [doc.channels.getByName(channelList[i-2])];
var lyr = app.activeDocument.artLayers.add();
lyr.name = doc.channels[i].name;
app.activeDocument.selection.selectAll();
app.activeDocument.selection.copy();
app.activeDocument.selection.deselect();
app.activeDocument.paste();

}
}
if (activeDocument.mode == DocumentMode.CMYK) {
alert("the doc is  CMYK");
for (var i = 3; i < doc.channels.length; i++) {
alert(doc.channels[i].name);
}
}

 

I just need to copy all the info in the channels I separated from a picture, whether is CMYK or RGB to layers, please help, thanks.

TOPICS
Actions and scripting , SDK , Windows
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Contributor , Jan 10, 2023 Jan 10, 2023

I found a solution, i used the code in the following thread:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/convert-all-alpha-channels-into-layers/m-p/13478902/page/2#M696903

 

But adding some lines and actions in PS in order to make what I needed, BUT.... I will really appreaciate if somebody can tell me how to make it work from the top of the channels to the bottom of the channels, right now it creates layers from the bottom to the top. here it is:

 

//code by c.pfaffenbichler

if (a

...
Translate
Community Expert , Jan 11, 2023 Jan 11, 2023

@AntonioPacheco – OK, I think that you need to change this line:

 

for (var m = theChannels.length-1; m >= 0; m--) {

 

to this: 

 

for (var m = 0; m < theChannels.length; m++) {

 

Full code with very limited testing:

 

//code by c.pfaffenbichler
if (app.documents.length > 0) {
    if (activeDocument.mode == DocumentMode.RGB || activeDocument.mode == DocumentMode.CMYK) {
        var theChannels = collectChannels();
        activeDocument.selection.deselect();
        // create layers;
        //
...
Translate
Adobe
Contributor ,
Jan 10, 2023 Jan 10, 2023

I need teh info from the selected areas turn into layers, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 10, 2023 Jan 10, 2023

I found a solution, i used the code in the following thread:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/convert-all-alpha-channels-into-layer...

 

But adding some lines and actions in PS in order to make what I needed, BUT.... I will really appreaciate if somebody can tell me how to make it work from the top of the channels to the bottom of the channels, right now it creates layers from the bottom to the top. here it is:

 

//code by c.pfaffenbichler

if (app.documents.length > 0) {
if (activeDocument.mode == DocumentMode.RGB || activeDocument.mode == DocumentMode.CMYK) {
var theChannels = collectChannels ();
activeDocument.selection.deselect();
// create layers;
for (var m = theChannels.length-1; m >= 0; m--) {
loadAndLayer (theChannels[m][1], theChannels[m][0], [0,0,0]);
app.doAction("action1","actionset")
};
app.doAction("action2","actionset")
};
};
////// collect layers //////
function collectChannels () {
// get number of layers;
var ref = new ActionReference();
//ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfChannels'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfChannels"));
// pixel dimensions;
var theWidth = applicationDesc.getUnitDoubleValue(stringIDToTypeID("width"));
var theHeight = applicationDesc.getUnitDoubleValue(stringIDToTypeID("height"));
var theRes = applicationDesc.getUnitDoubleValue(stringIDToTypeID("resolution"));
var thePixels = (theWidth*theRes/72)*(theHeight*theRes/72);
// process the channels;
var theChannels = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex(stringIDToTypeID( "channel" ), m);
var channelDesc = executeActionGet(ref);
// collect values;
var theName = channelDesc.getString(stringIDToTypeID('channelName'));
var theIndex = channelDesc.getInteger(stringIDToTypeID('itemIndex'));
var theID = channelDesc.getInteger(stringIDToTypeID('ID'));
if (channelDesc.hasKey(stringIDToTypeID('alphaChannelOptions')) == true) {
var theHistogram = channelDesc.getList(stringIDToTypeID('histogram'));
var value0 = theHistogram.getInteger(0);
// if not completely black;
if (value0 != thePixels) {
theChannels.push([theName, theIndex, theID])
} else {}
};
} catch (e) {};
};
return theChannels
};
//////
function loadAndLayer (theIndex, theName, theColor) {
var idnull = stringIDToTypeID( "null" );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
var idchannel = stringIDToTypeID( "channel" );
var idmake = stringIDToTypeID( "make" );
// =======================================================
var desc11 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putClass( idcontentLayer );
desc11.putReference( idnull, ref4 );
var desc12 = new ActionDescriptor();
var desc13 = new ActionDescriptor();
var desc14 = new ActionDescriptor();
desc14.putDouble( stringIDToTypeID( "red" ), theColor[0] );
desc14.putDouble( stringIDToTypeID( "grain" ), theColor[1] );
desc14.putDouble( stringIDToTypeID( "blue" ), theColor[2] );
var idRGBColor = stringIDToTypeID( "RGBColor" );
desc13.putObject( stringIDToTypeID( "color" ), idRGBColor, desc14 );
desc12.putString( stringIDToTypeID( "name" ), theName );
desc12.putObject( stringIDToTypeID( "type" ), stringIDToTypeID( "solidColorLayer" ), desc13 );
desc11.putObject( stringIDToTypeID( "using" ), idcontentLayer, desc12 );
executeAction( idmake, desc11, DialogModes.NO );
// remove layer mask;
try {
// =======================================================
var desc10 = new ActionDescriptor();
var ref2 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
ref2.putEnumerated( idchannel, idchannel, stringIDToTypeID( "mask" ) );
desc10.putReference( stringIDToTypeID( "null" ), ref2 );
executeAction( stringIDToTypeID( "delete" ), desc10, DialogModes.NO );
} catch (e) {};
// =======================================================
var desc2 = new ActionDescriptor();
desc2.putClass( stringIDToTypeID( "new" ), idchannel );
var ref1 = new ActionReference();
ref1.putEnumerated( idchannel, idchannel, idmask = stringIDToTypeID( "mask" ) );
desc2.putReference( stringIDToTypeID( "at" ), ref1 );
desc2.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "userMaskEnabled" ), stringIDToTypeID( "hideAll" ) );
executeAction( idmake, desc2, DialogModes.NO );
// =======================================================
var desc3 = new ActionDescriptor();
var desc4 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putIndex( idchannel, theIndex );
desc4.putReference( stringIDToTypeID( "to" ), ref2 );
var idpreserveTransparency = stringIDToTypeID( "preserveTransparency" );
desc4.putBoolean( stringIDToTypeID( "invert" ), true );
desc4.putBoolean( idpreserveTransparency, true );
desc3.putObject( stringIDToTypeID( "with" ), stringIDToTypeID( "calculation" ), desc4 );
executeAction( idapplyImageEvent = stringIDToTypeID( "applyImageEvent" ), desc3, DialogModes.NO );
};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2023 Jan 10, 2023

@AntonioPacheco wrote:

I will really appreaciate if somebody can tell me how to make it work from the top of the channels to the bottom of the channels, right now it creates layers from the bottom to the top. here it is:

 

I'm guessing the answer will be to reverse the for loop over the channels/layers. I'm not in front of a computer so I can't give you the code now... But knowing this, you can search the forum or web for info on JS for loops  - forwards and backwards. Look for the more common ++ increment loop examples as this appears to use -- decrement.

 

EDIT: You could also select the layers after they are created, then use Layer > Arrange > Reverse

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2023 Jan 11, 2023

@AntonioPacheco – OK, I think that you need to change this line:

 

for (var m = theChannels.length-1; m >= 0; m--) {

 

to this: 

 

for (var m = 0; m < theChannels.length; m++) {

 

Full code with very limited testing:

 

//code by c.pfaffenbichler
if (app.documents.length > 0) {
    if (activeDocument.mode == DocumentMode.RGB || activeDocument.mode == DocumentMode.CMYK) {
        var theChannels = collectChannels();
        activeDocument.selection.deselect();
        // create layers;
        //for (var m = theChannels.length-1; m >= 0; m--) {
        for (var m = 0; m < theChannels.length; m++) {
            loadAndLayer(theChannels[m][1], theChannels[m][0], [0, 0, 0]);
            app.doAction("action1","actionset")
        }
        app.doAction("action2","actionset")
    }
}
////// collect layers //////
function collectChannels() {
    // get number of layers;
    var ref = new ActionReference();
    //ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfChannels'));
    ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfChannels"));
    // pixel dimensions;
    var theWidth = applicationDesc.getUnitDoubleValue(stringIDToTypeID("width"));
    var theHeight = applicationDesc.getUnitDoubleValue(stringIDToTypeID("height"));
    var theRes = applicationDesc.getUnitDoubleValue(stringIDToTypeID("resolution"));
    var thePixels = (theWidth * theRes / 72) * (theHeight * theRes / 72);
    // process the channels;
    var theChannels = new Array;
    for (var m = 0; m <= theNumber; m++) {
        try {
            var ref = new ActionReference();
            ref.putIndex(stringIDToTypeID("channel"), m);
            var channelDesc = executeActionGet(ref);
            // collect values;
            var theName = channelDesc.getString(stringIDToTypeID('channelName'));
            var theIndex = channelDesc.getInteger(stringIDToTypeID('itemIndex'));
            var theID = channelDesc.getInteger(stringIDToTypeID('ID'));
            if (channelDesc.hasKey(stringIDToTypeID('alphaChannelOptions')) === true) {
                var theHistogram = channelDesc.getList(stringIDToTypeID('histogram'));
                var value0 = theHistogram.getInteger(0);
                // if not completely black;
                if (value0 != thePixels) {
                    theChannels.push([theName, theIndex, theID]);
                } else {}
            }
        } catch (e) {}
    }
    return theChannels;
}
//////
function loadAndLayer(theIndex, theName, theColor) {
    var idnull = stringIDToTypeID("null");
    var idcontentLayer = stringIDToTypeID("contentLayer");
    var idchannel = stringIDToTypeID("channel");
    var idmake = stringIDToTypeID("make");
    // =======================================================
    var desc11 = new ActionDescriptor();
    var ref4 = new ActionReference();
    ref4.putClass(idcontentLayer);
    desc11.putReference(idnull, ref4);
    var desc12 = new ActionDescriptor();
    var desc13 = new ActionDescriptor();
    var desc14 = new ActionDescriptor();
    desc14.putDouble(stringIDToTypeID("red"), theColor[0]);
    desc14.putDouble(stringIDToTypeID("grain"), theColor[1]);
    desc14.putDouble(stringIDToTypeID("blue"), theColor[2]);
    var idRGBColor = stringIDToTypeID("RGBColor");
    desc13.putObject(stringIDToTypeID("color"), idRGBColor, desc14);
    desc12.putString(stringIDToTypeID("name"), theName);
    desc12.putObject(stringIDToTypeID("type"), stringIDToTypeID("solidColorLayer"), desc13);
    desc11.putObject(stringIDToTypeID("using"), idcontentLayer, desc12);
    executeAction(idmake, desc11, DialogModes.NO);
    // remove layer mask;
    try {
        // =======================================================
        var desc10 = new ActionDescriptor();
        var ref2 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        ref2.putEnumerated(idchannel, idchannel, stringIDToTypeID("mask"));
        desc10.putReference(stringIDToTypeID("null"), ref2);
        executeAction(stringIDToTypeID("delete"), desc10, DialogModes.NO);
    } catch (e) {}
    // =======================================================
    var desc2 = new ActionDescriptor();
    desc2.putClass(stringIDToTypeID("new"), idchannel);
    var ref1 = new ActionReference();
    ref1.putEnumerated(idchannel, idchannel, idmask = stringIDToTypeID("mask"));
    desc2.putReference(stringIDToTypeID("at"), ref1);
    desc2.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskEnabled"), stringIDToTypeID("hideAll"));
    executeAction(idmake, desc2, DialogModes.NO);
    // =======================================================
    var desc3 = new ActionDescriptor();
    var desc4 = new ActionDescriptor();
    var ref2 = new ActionReference();
    ref2.putIndex(idchannel, theIndex);
    desc4.putReference(stringIDToTypeID("to"), ref2);
    var idpreserveTransparency = stringIDToTypeID("preserveTransparency");
    desc4.putBoolean(stringIDToTypeID("invert"), true);
    desc4.putBoolean(idpreserveTransparency, true);
    desc3.putObject(stringIDToTypeID("with"), stringIDToTypeID("calculation"), desc4);
    executeAction(idapplyImageEvent = stringIDToTypeID("applyImageEvent"), desc3, DialogModes.NO);
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 11, 2023 Jan 11, 2023

Excellent!!! Thank you so much, I did not think about that, maybe I was too tired yesterday, thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2023 Jan 11, 2023

You're welcome @AntonioPacheco 

 

I'm just curious what the "end game" is here?

 

Now that you have a black layer for each channel, now what?

 

Is this to facilitate printing separations via layers?

 

Are you then going to use the Export Layers to Files script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 12, 2023 Jan 12, 2023

Thank you for your comment! To be honest, is really weird, recently I jusr got a request from my managers that they don't want the separations in channels for specific cases of arts, they want it in layers so I just was looking for a faster way to do layers from the channels.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2023 Jan 12, 2023

Thanks, sounds like you don't know why, thanks anyway.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2023 Jan 23, 2023

You may try this spot-color plugin for Photoshop, it handles spot channels as if they were layers:

https://www.retouchxpress.eu/plugins/spot

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 23, 2023 Jan 23, 2023

thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 26, 2023 Jan 26, 2023

Hello community.  I would like to open this thread again.

 

Is it possible to add to this code the feature to also "set" the channel color to the copied layer? I mean you know taht we can select a color for the channel, right now the code only copies the information on each channel to a layer but it does not copy/set the color, I have to do it manually one by one when layers are generated, is there the posibility to also copy the color from the channel to the layer? Thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

@c.pfaffenbichler as this is your code, I thought that it was best to bring this topic to your attention...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 26, 2023 Jan 26, 2023

sorry for bothering to both of you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

It's not a bother for me, it is a challenge... Truth be told, I was expecting this to come up earlier!

 

Edit: Setting the values I can do, but getting them? I don't know how, or if it is even possible to get the colour values of a spot colour channel via scripting. A spot colour channel can use either an installed Color Book (.acb file) link/reference – or it can use Colour Picker values (HSB, RGB or Lab). 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

There is an AlternateSpotColors - Tag 0x042b (18 bytes) in the binary data of a PSD file... So perhaps this can be decoded?

 

https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/

 

0x042B

1067

(Photoshop CS)Alternate Spot Colors. 2 bytes (version = 1), 2 bytes channel count, following is repeated for each count: 4 bytes channel ID, Color: 2 bytes for space followed by 4 * 2 byte color component. This resource is not read or used by Photoshop.

 

For a PANTONE Blue 072 C, ExifTool reports this as:

 

AlternateSpotColors = .........P
  - Tag 0x042b (18 bytes):
      3a9a: 00 01 00 01 00 00 00 02 00 07 06 e5 10 cc e2 50 [...............P]
      3aaa: 00 00                                           [..]
  

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 26, 2023 Jan 26, 2023

In fact I was looking for something like this, great that you were able to find it! for now I am already at home, my research will continue tomorrow

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2023 Jan 26, 2023

I mean you know taht we can select a color for the channel, 

Just to make sure: What color did you select? A custom one or a Pantone color or …? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 27, 2023 Jan 27, 2023

Thanks for your answer! What I use the most is alpha channels with pantone colors (Solid Coated), when I create alpha channels with the information I need, I normaly select a pantone color here in the channel, the script has worked perfect all this time! I just was wondering if is possible to also get the color I chose and copy/set it in the new created layer (maybe as a color overlay in the layer?? not sure, I am not too familiar with photoshop script)

 

thank you!

 

AntonioPacheco_0-1674822806371.png

AntonioPacheco_1-1674822815467.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

@AntonioPacheco – I think that @c.pfaffenbichler was asking for a screenshot of the colour swatch, when you click the orange colour swatch – what is shown, a colour library or colour picker?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

@Stephen Marsh wrote:

@AntonioPacheco – I think that @c.pfaffenbichler was asking for a screenshot of the colour swatch, when you click the orange colour swatch – what is shown, a colour library or colour picker?


Indeed; but based on the name it seems likely that it was not a Color Book-color anyway but a custom one. 

Those should be accessible via Script. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 27, 2023 Jan 27, 2023

You probably mean this one right?

AntonioPacheco_0-1674824185762.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

That’s bad; Color Books-colors seem to be »complicated« … 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

If you are using Pantone Color definitions why didn’t you name the Spot Channel accordingly? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 27, 2023 Jan 27, 2023

That could be the best solution possible, pretty nice suggestion!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines