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
Community Expert ,
Jan 29, 2023 Jan 29, 2023

Could you provide a sample file? 

One work-around might be using »Merge Spot Channel«. 

 

// determine spot channel colors;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
    ////// collect layers //////
    var theChannels = collectSpotChannels ();
    alert ("spot channels\n"+theChannels.join("\n"));
    };
////////////////////////////////////
////// collect layers //////
function collectSpotChannels () {
    var myDocument = activeDocument;
// get number of layers;
    var ref = new ActionReference();
    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 channelOpt = channelDesc.getObjectValue(stringIDToTypeID("alphaChannelOptions"));
    var theColor = channelOpt.getObjectValue(stringIDToTypeID("color"));
    var colorIndicates = channelOpt.getEnumerationValue(stringIDToTypeID("colorIndicates"));
    var theHistogram = channelDesc.getList(stringIDToTypeID('histogram'));
    var value0 = theHistogram.getInteger(0);
// if not completely black and not alpha channel;
    if (value0 != thePixels && colorIndicates == 1399877492) {
// if hsb-color;
        if (typeIDToStringID(channelOpt.getObjectType(channelOpt.getKey(1))) == "HSBColorClass") {
            theChannels.push([theName, theIndex, theID, [theColor.getUnitDoubleValue(stringIDToTypeID("hue")), theColor.getUnitDoubleValue(stringIDToTypeID("saturation")), theColor.getUnitDoubleValue(stringIDToTypeID("brightness"))]])
        }
// if book color; 
        else {
// create duplicate to use merge spot channel to determine color;
            var theDup = myDocument.duplicate("thedup", true);
            fillWithColor ("white");
            selectChannel (theIndex);
            fillWithColor ("black");
            executeAction( stringIDToTypeID( "mergeSpotChannel" ), undefined, DialogModes.NO );
            var aColor = eyedropperTool(1,1);
            theDup.close(SaveOptions.DONOTSAVECHANGES);
            app.activeDocument = myDocument;
            theChannels.push([theName, theIndex, theID, [aColor.hsb.hue, aColor.hsb.saturation, aColor.hsb.brightness]])
        };
    } else {}
    };
    } catch (e) {};
    };
    return theChannels
    };
////// select channel //////
function selectChannel (theIndex) {
    var desc6 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putIndex( stringIDToTypeID( "channel" ), theIndex );
//        ref1.putName( stringIDToTypeID( "channel" ), "PANTONE 1925 C" );
    desc6.putReference( stringIDToTypeID( "null" ), ref1 );
executeAction( stringIDToTypeID( "select" ), desc6, DialogModes.NO );
};
////// fill with color //////
function fillWithColor (theColor) {
    var desc8 = new ActionDescriptor();
    desc8.putEnumerated( stringIDToTypeID( "using" ), stringIDToTypeID( "fillContents" ), stringIDToTypeID(theColor) );
    desc8.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
    desc8.putEnumerated(stringIDToTypeID( "mode" ), stringIDToTypeID( "blendMode" ),stringIDToTypeID( "normal" ));
executeAction( stringIDToTypeID( "fill" ), desc8, DialogModes.NO );
};
////// simulate eyedropper with color sampler //////
function eyedropperTool (theX, theY) {
// set units;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// set sampler;
try {
var theSampler = activeDocument.colorSamplers.add([theX, theY]);
var theColor = theSampler.color;
theSampler.remove();
} catch (e) {return};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theColor
};

 

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 30, 2023 Jan 30, 2023

Yes! here is a sample file, the MTV 2 has already the channels turned into layers, but the layers are black, I was wodering if i possible to grab the values/colors of the channels and paste it in the layers. Thanks for the support

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 30, 2023 Jan 30, 2023

The last Script I posted canbe used to determine Spot Channels’ colors, feel free to combine the Scripts as necessary. 

Screenshot 2023-01-30 at 17.24.08.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
Contributor ,
Jan 30, 2023 Jan 30, 2023
LATEST

thank you so much @c.pfaffenbichler 

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