質問

In Photoshop it is possible to Set Selection to the Transparency Channel of a layer by pressing ctrl/cmd and clicking on the thumbnail of the layer in the layer pane. When recording this as an action, it is displayed "Set Selection To: transparency channel of layer 'LAYERNAME'".

Is it possible to duplicate this functionality using Photoshop's Extendscript for use in a Photoshop plugin and how would one accomplish this? I need to dynamically open files and select a certain layer in this fashion.

Thank you for your time.

役に立ちましたか?

解決

Was trying to figure out exactly this just yesterday. From pouring over the documentation I concluded that you have 2 basic options:

  1. Create an action in Photoshop that simply does the selection and invoke it from your script using app.doAction([actionName], [actionSetName]).

  2. Use the script listener plugin to extract your own function to do the selection and use that directly in your script.

Option 1 seems a little "safer", but it does introduce a dependency on having an action with a specific name and function presently loaded in PS; which is the suck.

Option 2 is a bit harder to maintain, but it encapsulates all dependencies within itself rather nicely. If you want to go with that then try adding and invoking this function in your script (slightly cleaner version of what you'd get from the script listener):

function SelectTransparency()
{
    var idChnl = charIDToTypeID( "Chnl" );

    var actionSelect = new ActionReference();
    actionSelect.putProperty( idChnl, charIDToTypeID( "fsel" ) );     

    var actionTransparent = new ActionReference();    
    actionTransparent.putEnumerated( idChnl, idChnl, charIDToTypeID( "Trsp" ) );

    var actionDesc = new ActionDescriptor();
    actionDesc.putReference( charIDToTypeID( "null" ), actionSelect );
    actionDesc.putReference( charIDToTypeID( "T   " ), actionTransparent );

    executeAction( charIDToTypeID( "setd" ), actionDesc, DialogModes.NO );
}

Just make sure you have the desired document and a valid layer active before calling the method. Hope it helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top