Skip to main content
Participant
February 28, 2020
Answered

Group clipping mask

  • February 28, 2020
  • 3 replies
  • 882 views

My Layer group has a clipping mask on it and I want to know if it is possble to apply the clipping mask to the layers without flattening the layers in the group. I need it to remain in layers so I can export for Animation

This topic has been closed for replies.
Correct answer Chuck Uebele

Try this script. YOU HAVE TO HAVE THE GROUP CLIPPING MASK SELECTED! There is no error checking, so it will also clip to any layer, like an adjustment layer, which will just show the entire image of the clipping layer.

 

#target photoshop
var doc = activeDocument;
var cLay = doc.activeLayer;
selNextLayer ();
var gp = doc.activeLayer;
var layA =[];

for(var i=0;i<gp.layers.length;i++){
    layA.push(gp.layers[i]);
    };

for(var i=0;i<layA.length;i++){
    doc.activeLayer = cLay;
    dupe ();
    var mLay = doc.activeLayer;
    mLay.move (layA[i], ElementPlacement.PLACEBEFORE);
    mLay.grouped = true;    
    }

cLay.remove();

function dupe(){
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );    
    }

function selNextLayer(){
    var idslct = charIDToTypeID( "slct" );
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idBckw = charIDToTypeID( "Bckw" );
            ref1.putEnumerated( idLyr, idOrdn, idBckw );
        desc2.putReference( idnull, ref1 );
        var idMkVs = charIDToTypeID( "MkVs" );
        desc2.putBoolean( idMkVs, false );
        var idLyrI = charIDToTypeID( "LyrI" );
            var list1 = new ActionList();
            list1.putInteger( 2 );
        desc2.putList( idLyrI, list1 );
    executeAction( idslct, desc2, DialogModes.NO );    
    }

 

3 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
February 29, 2020

Try this script. YOU HAVE TO HAVE THE GROUP CLIPPING MASK SELECTED! There is no error checking, so it will also clip to any layer, like an adjustment layer, which will just show the entire image of the clipping layer.

 

#target photoshop
var doc = activeDocument;
var cLay = doc.activeLayer;
selNextLayer ();
var gp = doc.activeLayer;
var layA =[];

for(var i=0;i<gp.layers.length;i++){
    layA.push(gp.layers[i]);
    };

for(var i=0;i<layA.length;i++){
    doc.activeLayer = cLay;
    dupe ();
    var mLay = doc.activeLayer;
    mLay.move (layA[i], ElementPlacement.PLACEBEFORE);
    mLay.grouped = true;    
    }

cLay.remove();

function dupe(){
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );    
    }

function selNextLayer(){
    var idslct = charIDToTypeID( "slct" );
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idBckw = charIDToTypeID( "Bckw" );
            ref1.putEnumerated( idLyr, idOrdn, idBckw );
        desc2.putReference( idnull, ref1 );
        var idMkVs = charIDToTypeID( "MkVs" );
        desc2.putBoolean( idMkVs, false );
        var idLyrI = charIDToTypeID( "LyrI" );
            var list1 = new ActionList();
            list1.putInteger( 2 );
        desc2.putList( idLyrI, list1 );
    executeAction( idslct, desc2, DialogModes.NO );    
    }

 

Legend
February 29, 2020
What do you mean by "apply the clipping mask".
Could you show the layer structure with a screenshot of the layer panel?
 
Chuck Uebele
Community Expert
Community Expert
February 29, 2020

You would have to do that manually, by duplicating the clipping layer and moving the dupe to each layer in the group, and clip to each layer. If you are doing this a lot, a script could be written to automate it.

Participant
February 29, 2020

thats what I ended up doing. a script I dont know how to do