Highlighted

Scripting - Set selection to layer mask

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

I'm trying to set the selected area of a group to the layer mask, then paste and image into it. 

I have it selecting the group and pasting, but not sure how to make it set the selection. At the moment it pastes to the middle of the document.

If i were doing it manually, i'd command+click the layer mask thumbnail

 

    // Layers
    var layers = app.activeDocument.layers;
    var layerName = "Card " + i;
    var myLayer = layers[layerName];
    app.activeDocument.activeLayer = myLayer;
    
    // Selection
    
    
    app.documents[0].paste();

 

I could define the locations manually but then would need to do it for each layer, and there are over 20 layers

TOPICS
Actions and scripting, How to, Mac

Views

72

Likes

Translate

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

Scripting - Set selection to layer mask

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

I'm trying to set the selected area of a group to the layer mask, then paste and image into it. 

I have it selecting the group and pasting, but not sure how to make it set the selection. At the moment it pastes to the middle of the document.

If i were doing it manually, i'd command+click the layer mask thumbnail

 

    // Layers
    var layers = app.activeDocument.layers;
    var layerName = "Card " + i;
    var myLayer = layers[layerName];
    app.activeDocument.activeLayer = myLayer;
    
    // Selection
    
    
    app.documents[0].paste();

 

I could define the locations manually but then would need to do it for each layer, and there are over 20 layers

TOPICS
Actions and scripting, How to, Mac

Views

73

Likes

Translate

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
Oct 05, 2020 0
Adobe Community Professional ,
Oct 05, 2020

Copy link to clipboard

Copied

What exactly are you making a selection of? Any you want to paste the same selection in mulitple layers? Can you show an example of what you're trying to achieve? Using scripListener would be the best way to handle this, where you could have it generate the code to have a layer mask selected.

 

This code should select the layer mask of the current layer:

var idslct = charIDToTypeID( "slct" );
    var desc36 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref8 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref8.putEnumerated( idChnl, idChnl, idMsk );
    desc36.putReference( idnull, ref8 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc36.putBoolean( idMkVs, false );
executeAction( idslct, desc36, DialogModes.NO );

Likes

Translate

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
Reply
Loading...
Oct 05, 2020 0
LEGEND ,
Oct 05, 2020

Copy link to clipboard

Copied

What are you actually trying to automate? 

 

This should load the Layer Mask as a Selection? 

// load layer mask as selection;
// 2020, use it at your own risk;
if (app.documents.length > 0) {main()};
//////
function main () {
// check for layer mask;
var theCheck = hasLayerMask();
if (theCheck == true) {
var idchannel = stringIDToTypeID( "channel" );
var idmask = stringIDToTypeID( "mask" );
// load;
loadSelectionOfLayerMask();
}
};
////// has layer mask //////
function hasLayerMask () {  
    var m_Dsc01, m_Ref01;
    m_Ref01 = new ActionReference();
    m_Ref01.putEnumerated(stringIDToTypeID("layer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    m_Dsc01 = executeActionGet(m_Ref01);
    return m_Dsc01.hasKey(charIDToTypeID("Usrs"));
    };
////// load layer mask //////
function loadSelectionOfLayerMask() {  
    try {
        var idchannel = stringIDToTypeID( "channel" );
        var desc70 = new ActionDescriptor();
        var ref9 = new ActionReference();
        ref9.putProperty( idchannel, stringIDToTypeID( "selection" ) );
    desc70.putReference( stringIDToTypeID( "null" ), ref9 );
        var ref10 = new ActionReference();
        ref10.putEnumerated( idchannel, idchannel, stringIDToTypeID( "mask" ) );
    desc70.putReference( stringIDToTypeID( "to" ), ref10 );
    executeAction( stringIDToTypeID( "set" ), desc70, DialogModes.NO );
    } catch (_error) {alert (_error)}
    };

Likes

Translate

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
Reply
Loading...
Oct 05, 2020 0
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

I'm trying to automate copying images from one file into a psd. Currently I copy the image, command+click the layer mask for the first group ( Card 1) then pasting. The copy the second image into Card 2 etc.

 

it's currently copying into the correct groups, but not the correct location

Likes

Translate

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
Reply
Loading...
Oct 05, 2020 0
LEGEND ,
Oct 05, 2020

Copy link to clipboard

Copied

Have you tried loading the Layer Masks as per above code? 

 

Copy/pasting in a Script is often uselessly wasteful and placing or duplicating might work faster, but frankly I don’t understand your description. What are you really copying – images, layers, …? 

Likes

Translate

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
Reply
Loading...
Oct 05, 2020 0
Desbrina LATEST
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

Currently, for each image, i'm doing a command+a, command+c, going to the the pds, clicking the group, command+click on the layer mask then command+v

This means the images are pasted into generally the correct location, i don't have to do much aligning of them.

 

Duplicating pastes it in the wrong location.

 

As the screenshot below, i want to paste into each of the windows. Each window has a group associated with a layer mask removing all expect the window.

Screenshot 2020-10-05 at 15.05.23.png

 

I tried your code, it worked for the first group, but then didn't select the second group and pasted in the center

Likes

Translate

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
Reply
Loading...
Oct 05, 2020 0