load alpha channels convert selection to layer

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

vbrajan

load alpha channels convert selection to layer

Post by vbrajan »

Thanks Paul. It is working fine
elentiv

load alpha channels convert selection to layer

Post by elentiv »

Hi

The Mike Hale script works really fine, but I would ask if is possible to perform a "copy" of each alpha channel into new layer

The problem is quite the same as vbrajan
I have a document with many alpha channel ( each one with a name that i have assigned) and i need to create for each alpha channel an exact copy on a new layer
The steps i'm looking for are:
select alpha channel ,
perform a select all ( of the alpha channel)
copy (the alpha channel)
and past the channel copy into new layer ( with the same alpha channel name)
and loop the same for the other alpha channel in my document

I hope for an help
elen
Mike Hale

load alpha channels convert selection to layer

Post by Mike Hale »

How about this...
Code: Select allfunction copyAlphaToLayer( alphaName ) {
    var lyr = app.activeDocument.artLayers.add();
    lyr.name = alphaName;
    var desc = new ActionDescriptor();
        var desc1 = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putName( charIDToTypeID('Chnl'), alphaName );
        desc1.putReference( charIDToTypeID('T   '), ref );
    desc.putObject( charIDToTypeID('With'), charIDToTypeID('Clcl'), desc1 );
    executeAction( charIDToTypeID('AppI'), desc, DialogModes.NO );
    return lyr;
};
for( var c = 0; c < app.activeDocument.channels.length;c++ ){
    if( app.activeDocument.channels[c].kind == ChannelType.SELECTEDAREA  ) {
          copyAlphaToLayer( app.activeDocument.channels[c].name );
    }
}
elentiv

load alpha channels convert selection to layer

Post by elentiv »

Hi Mike
thanks for your replay
I'm newbe
I tried the script but He tell me execution finished but nothing happen
Where I'm wrong?
I notice in the script that it perform an "apply Image " and if it is possible I would prefer a " copy" instead
elentiv

load alpha channels convert selection to layer

Post by elentiv »

I changed channelType.SELECTEDAREA with channelType.MASKEDAREA and it runs perfectly.
I hope that it will be the chance to use a " Copy" command instead of Apply Image

Thank You again
Mike Hale

load alpha channels convert selection to layer

Post by Mike Hale »

I used Apply Image because it is faster, shorter, and gives better results than going through the clipboard(copy/paste). Using the clipboard almost always changes the gamma of the channel when pasted into a layer.

However here is one way to copy/paste the alpha channels into layers.
Code: Select allfunction copyAlphaToLayer( alphaChannel ){
    var lyr = app.activeDocument.artLayers.add();
    lyr.name = alphaChannel.name;
    var compChannels = app.activeDocument.activeChannels;
    app.activeDocument.activeChannels = [ alphaChannel  ];
    app.activeDocument.selection.selectAll();
    app.activeDocument.selection.copy();
    app.activeDocument.selection.deselect();
    app.activeDocument.activeChannels = compChannels;
    app.activeDocument.paste();
}
var doc = activeDocument;
var lyr = doc.activeLayer;
var cnt = doc.channels.length;
for(var i = 1 ;i < cnt;i++){
   if(activeDocument.channels.kind != ChannelType.MASKEDAREA) {continue}
   copyAlphaToLayer( doc.channels );
}