Skip to main content
Participating Frequently
December 31, 2008
Question

Load Transparency from a layer?

  • December 31, 2008
  • 5 replies
  • 2899 views
How can I load the transparency from a given layer as a selection via script? In the way as if you cmd-klick on a layer palette icon and have the solid pixels in that layer selected.
There is the Selection.load (from: Channel ), and in the Photoshop menue there is also the option to select the Transparency of the active channel but I can't find anything like that in the object Library.

Thanks for your help, Joerg
This topic has been closed for replies.

5 replies

Inspiring
June 25, 2009

I'm trying to do the same thing and got the code working, but I would also like to specify the mode when selecting.

Specifically I would like to add the transparencys from several layers together to get their combined transparency. In other words, the equivalent of CTRL-SHIFT-Click on the layer thumbnail.

How would I do this?

thanks

Ludde

Paul Riggott
Inspiring
June 25, 2009

Give this a try....

loadTransparencyAll();

function loadTransparencyAll() {
   var desc13 = new ActionDescriptor();
        var ref10 = new ActionReference();
        ref10.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
    desc13.putReference( charIDToTypeID('null'), ref10 );
        var ref11 = new ActionReference();
        ref11.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
        ref11.putName( charIDToTypeID('Lyr '), activeDocument.artLayers[0].name );
    desc13.putReference( charIDToTypeID('T   '), ref11 );
try{
    executeAction( charIDToTypeID('setd'), desc13, DialogModes.NO );
}catch(e){}
};

Paul Riggott
Inspiring
February 5, 2009
Here is a variation on X's code
The layer must be the active one...


selectTransparency();



function selectTransparency() {

function cTID(s) { return app.charIDToTypeID(s); };

function sTID(s) { return app.stringIDToTypeID(s); };

var desc27 = new ActionDescriptor();

var ref3 = new ActionReference();

ref3.putProperty( cTID('Chnl'), cTID('fsel') );

desc27.putReference( cTID('null'), ref3 );

var ref4 = new ActionReference();

ref4.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Trsp') );

desc27.putReference( cTID('T '), ref4 );

executeAction( cTID('setd'), desc27, DialogModes.NO );

};

Participant
February 5, 2009
I'm also trying to achieve this, but i'm not sure how to use the code you gave. can you give an example? thanks
Participating Frequently
January 2, 2009
Thanks a lot!
Known Participant
December 31, 2008
From xtools/xlib/stdlib.js:

Stdlib = {}

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };


//
// Select either the Transparency or Mask Channel
// kind - "Trsp" or "Msk "
//
Stdlib.loadSelection = function(doc, layer, kind, invert) {
function _ftn() {
var desc = new ActionDescriptor(); // Set

var cref = new ActionReference(); // Channel Selection
cref.putProperty(cTID("Chnl"), cTID("fsel"));
desc.putReference(cTID("null"), cref);

var tref = new ActionReference(); // Channel Kind ("Trsp" or "Msk ")
tref.putEnumerated(cTID("Chnl"), cTID("Chnl"), cTID(kind));
desc.putReference(cTID("T "), tref);
if (invert == true) {
desc.putBoolean(cTID("Invr"), true);
}
executeAction(cTID("setd"), desc, DialogModes.NO);
}
_ftn));
};
Stdlib.selectTransparencyChannel = function(doc, layer, invert) {
Stdlib.loadSelection(doc, layer, "Trsp", invert);
};
Stdlib.selectMaskChannel = function(doc, layer, invert) {
Stdlib.loadSelection(doc, layer, "Msk ", invert);
};



-X