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

load selection to selected layers

Enthusiast ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

How can I make a Load Selection for all selected layers?
Without pressing ctrl+ Mouse Click to select each layer every time


200.jpgexpand image

TOPICS
Actions and scripting , SDK

Views

1.1K
Translate

Report

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 1 Correct answer

Community Expert , Sep 14, 2023 Sep 14, 2023

@Mohamed Hameed 

 

You can use an action:

 

2023-09-15_11-44-21.pngexpand image

 

A script has the added bonus of being able to offer a single history step:

 

/*
Load Selected Layers Transparency to Selection.jsx
Stephen Marsh, 8th September 2021
v1.0
NOTE: Previously selected layers are deselected, it would be nice to retain the selected layers...
*/

function loadSelLayersTransparency() {

    // Select all layers (ignores Background layer, ignores visibility)
    app.runMenuItem(stringIDToTypeID('selectAllLayers'));

    // Cr
...

Votes

Translate
Adobe
Community Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

@Mohamed Hameed 

 

You can use an action:

 

2023-09-15_11-44-21.pngexpand image

 

A script has the added bonus of being able to offer a single history step:

 

/*
Load Selected Layers Transparency to Selection.jsx
Stephen Marsh, 8th September 2021
v1.0
NOTE: Previously selected layers are deselected, it would be nice to retain the selected layers...
*/

function loadSelLayersTransparency() {

    // Select all layers (ignores Background layer, ignores visibility)
    app.runMenuItem(stringIDToTypeID('selectAllLayers'));

    // Create temp merged layer
    mergedLayer();

    // Rename layer
    app.activeDocument.activeLayer.name = "_temp";

    // Load layer transparency
    loadLayerTrans();

    // Remove temp merged layer
    app.activeDocument.activeLayer.remove();


    /****************** Functions ******************/

    function mergedLayer() {
        var idmergeLayersNew = stringIDToTypeID("mergeLayersNew");
        var desc291 = new ActionDescriptor();
        var idduplicate = stringIDToTypeID("duplicate");
        desc291.putBoolean(idduplicate, true);
        executeAction(idmergeLayersNew, desc291, DialogModes.NO);
    }

    function loadLayerTrans() {
        var idset = stringIDToTypeID("set");
        var desc323 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref75 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idselection = stringIDToTypeID("selection");
        ref75.putProperty(idchannel, idselection);
        desc323.putReference(idnull, ref75);
        var idto = stringIDToTypeID("to");
        var ref76 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idchannel = stringIDToTypeID("channel");
        var idtransparencyEnum = stringIDToTypeID("transparencyEnum");
        ref76.putEnumerated(idchannel, idchannel, idtransparencyEnum);
        desc323.putReference(idto, ref76);
        executeAction(idset, desc323, DialogModes.NO);
    }
}

// Single history step
app.activeDocument.suspendHistory("Load Selected Layers Transparency to Selection", "loadSelLayersTransparency()");

 

Remove or comment out the following to only use the selected layers instead of all layers:

 

// Select all layers (ignores Background layer, ignores visibility)
    app.runMenuItem(stringIDToTypeID('selectAllLayers'));

Votes

Translate

Report

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
Enthusiast ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

@Stephen Marsh 

Thank you very much for helping me, sir

Votes

Translate

Report

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

You're welcome!

 

There may be other ways*, this is just the way that naturally came to me.

*loop over all layers, load transparency as selection with modifier to add to selection.

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

The following code would work for pixel layers, but would disregard Layers Masks and Vector Masks. 

So in that regard your approach is actually more reliable. 

// load selection of selected layers;
// 2023, use it at your own risk;
if (documents.length > 0) {
var theSelectedLayers = collectSelectedLayers ();
var theAdd = false;
for (var m = 0; m < theSelectedLayers.length; m++) {
loadTransparencyAsSelection (theSelectedLayers[m][2], false, theAdd);
theAdd = true;
}
};
////// load transparency of layer //////
function loadTransparencyAsSelection (theID, theInvert, theAdd) {
try {
var idchannel = stringIDToTypeID( "channel" );
if (theAdd == true) {
    var desc7 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated( idchannel, idchannel, stringIDToTypeID( "transparencyEnum" ) );
    ref1.putIdentifier( stringIDToTypeID( "layer" ), theID );
    desc7.putReference( stringIDToTypeID( "null" ), ref1 );
    var ref2 = new ActionReference();
    var idchannel = stringIDToTypeID( "channel" );
    var idselection = stringIDToTypeID( "selection" );
    ref2.putProperty( idchannel, idselection );
    desc7.putReference( stringIDToTypeID( "to" ), ref2 );
    executeAction( stringIDToTypeID( "add" ), desc7, DialogModes.NO );}
else {
    var desc7 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putProperty( idchannel, stringIDToTypeID( "selection" ) );
    desc7.putReference( stringIDToTypeID( "null" ), ref3 );
    var ref4 = new ActionReference();
    ref4.putEnumerated( idchannel, idchannel, stringIDToTypeID( "transparencyEnum" ) );
    ref4.putIdentifier( stringIDToTypeID( "layer" ), theID );
    desc7.putReference( stringIDToTypeID( "to" ), ref4 );
    executeAction( stringIDToTypeID( "set" ), desc7, DialogModes.NO )
};
} catch (e) {}
};
////// collect bounds of selected layers //////
function collectSelectedLayers () {
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// get selected layers;
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if (desc.getBoolean(stringIDToTypeID("hasBackgroundLayer")) == true) {var theAdd =0}
else {var theAdd = 1};
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
// run through selected layers;
for(var i=0;i<c;i++){
var theIndex = desc.getReference( i ).getIndex()+theAdd;    
// get id for solid color layers;
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Lyr "), theIndex ); 
var layerDesc = executeActionGet(ref);
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
/*var theClippingMasked = layerDesc.getBoolean(stringIDToTypeID ("group"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
var theXCenter = theseBounds[0]+(theseBounds[2]-theseBounds[0])/2;
var theYCenter = theseBounds[1]+(theseBounds[3]-theseBounds[1])/2;*/
selectedLayers.push([theName, theIndex, theIdentifier/*, theseBounds, theXCenter, theYCenter*/]);
} catch (e) {};
};
// if only one:
}else{
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
try {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
/*var theClippingMasked = layerDesc.getBoolean(stringIDToTypeID ("group"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
var theXCenter = theseBounds[0]+(theseBounds[2]-theseBounds[0])/2;
var theYCenter = theseBounds[1]+(theseBounds[3]-theseBounds[1])/2;*/
selectedLayers = [[theName, theIndex, theIdentifier/*, theseBounds, theXCenter, theYCenter*/]]
} catch (e) {};
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return selectedLayers;
};

Votes

Translate

Report

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
Enthusiast ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 

When I tried the code, I saw this message

Untitled-1.jpgexpand image
Is this because the file has background

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

No, it works with and without a Background Layer. 

What is the alert you get? 

Votes

Translate

Report

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
Enthusiast ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

Have you tried running the script outside of ESTK, directly in Photoshop?

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible? 

What is the image’s Color Mode etc.? 

Votes

Translate

Report

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
Enthusiast ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler  Ok sir
SS.jpgexpand image

quote

What is the image’s Color Mode etc.?

 
Color Mode (RGB/8)

when running the script outside of ESTK, directly in Photoshop?

this message show to me
12.jpgexpand image

 

 error show in line number 48
10.jpgexpand image

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

The Panel names being written in All Caps seems peculiar to me (Mac user myself), which version of Photoshop are you using? 

Can you provide a sample file (feel free to black out all design elements)? 

Votes

Translate

Report

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
Enthusiast ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 

Is the problem in the Photoshop version? I have a version of Photoshop CS5. I know it is old, but this is due to my work circumstances.

Votes

Translate

Report

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 ,
Sep 16, 2023 Sep 16, 2023

Copy link to clipboard

Copied

I work with Photoshop 2024, so if you want to pursue a Scripting approach (despite the existing Action-approach) your problem with CS5 is yours to fix. 

Votes

Translate

Report

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 ,
Sep 16, 2023 Sep 16, 2023

Copy link to clipboard

Copied

If the issue is that the Action Manager code isn't compatible with your old version, then you can either use older supported AM code, or use supported DOM code instead.

 

try {
app.activeDocument.backgroundLayer;
    alert("A Background layer exists!");
} catch (e) {
    alert("No Background layer exists!");
}

 

 

Votes

Translate

Report

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 ,
Sep 17, 2023 Sep 17, 2023

Copy link to clipboard

Copied

And if the images always have a background Layer the whole check and the variable theAdd are useless and could be removed. 

 

@Mohamed Hameed , didn’t you use a function called »getSelectedLayersIdx« (or something similar) in one of your other projects? 

If that works then you can also adapt it to collect IDs instead of (or additional to) indices. 

Votes

Translate

Report

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
Enthusiast ,
Sep 17, 2023 Sep 17, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 
I didn't understand what you mean
Is this a modification within the code or what?

Votes

Translate

Report

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 ,
Sep 17, 2023 Sep 17, 2023

Copy link to clipboard

Copied

LATEST

You can modify the code anyway you want or need to adapt it to Photoshop CS5. 

Votes

Translate

Report

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 ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler â€“ Nice one! Now I can see why this method was beyond my reach.

Votes

Translate

Report

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