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

Load Transparency from a layer?

New Here ,
Dec 31, 2008 Dec 31, 2008
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
TOPICS
Actions and scripting
2.8K
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
Adobe
Explorer ,
Dec 31, 2008 Dec 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
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
New Here ,
Jan 02, 2009 Jan 02, 2009
Thanks a lot!
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
New Here ,
Feb 05, 2009 Feb 05, 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
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
Valorous Hero ,
Feb 05, 2009 Feb 05, 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 );

};

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
Explorer ,
Jun 25, 2009 Jun 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

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
Valorous Hero ,
Jun 25, 2009 Jun 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){}
};

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
Guru ,
Jun 25, 2009 Jun 25, 2009

The function below will add a layer trans to the selection like ctrl-shift-clicking in the layers icon. Note there needs to be an active selection so use the other function posted to load one layer trans then use the function below to add as many layers as you need.

function addLayerTransToSelection( layerName ){
     try{
          var desc = new ActionDescriptor();
               var ref = new ActionReference();
               ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
               ref.putName( charIDToTypeID( "Lyr " ), layerName );
          desc.putReference( charIDToTypeID( "null" ), ref );
               var ref1 = new ActionReference();
               ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
          desc.putReference( charIDToTypeID( "T   " ), ref1 );
          executeAction( charIDToTypeID( "Add " ), desc, DialogModes.NO );
          return true;
     }catch(e){}
     return false;
}

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
Explorer ,
Jun 26, 2009 Jun 26, 2009

Thanks, this seems to be working except for one thing. If two or more layers have the same name only one of them gets selected.

How should I do to use a reference to the layer instead of the name?

thanks

/Ludde

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
Guru ,
Jun 26, 2009 Jun 26, 2009
LATEST

You can not use a scripting API reference when working with action manager API. You could add by index, but the action manager index for a layer is not the same as the scripting layer index.

If your workflow allows you could make the layer you want to add active, get the action manager index, add by that index and restore the active layer.

function addLayerTransToSelection( layerIndex ){

     try{

          var desc = new ActionDescriptor();

               var ref = new ActionReference();

               ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );

               ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

               ref.putIndex(charIDToTypeID( "Lyr " ), layerIndex );

               //ref.putName( charIDToTypeID( "Lyr " ), layerName );

          desc.putReference( charIDToTypeID( "null" ), ref );

               var ref1 = new ActionReference();

               ref1.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );

          desc.putReference( charIDToTypeID( "T   " ), ref1 );

          executeAction( charIDToTypeID( "Add " ), desc, DialogModes.NO );

          return true;

     }catch(e){alert(e);}

     return false;

}

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var index = executeActionGet(ref).getInteger( stringIDToTypeID( 'itemIndex' ) );

addLayerTransToSelection( index );

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