Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How to release clipped layers

Contributor ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

How to release clipped layers with javascript? I need to write a script which will release all clipped layers.

P.S. Number of clipped layers are not always 3 (like on example below)

Screenshot 2020-05-20 at 8.08.34 AM.png

TOPICS
Actions and scripting, How to

Views

3.2K

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 22, 2020 May 22, 2020
OK, so layer A is selected. What now? Is it that A1/A2/A3 should then be unclipped, while the clipped layers of B and C remain unchanged? What you require is not clear to me... // Release clipping layers from base layer #target photoshop app.bringToFront(); function main() { app.runMenuItem(charIDToTypeID("GrpL")); app.runMenuItem(charIDToTypeID("GrpL")); } app.activeDocument.suspendHistory("Release clipping layers", "main()"); Presuming that the "base" layer A is selected, the...

Likes

Translate

Translate
Adobe Community Professional ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

The following code will release single or multiple selected clipped layers...

 

Raw SL Code:

 

 

var idUngr = charIDToTypeID( "Ungr" );
    var desc24 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref14 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref14.putEnumerated( idLyr, idOrdn, idTrgt );
    desc24.putReference( idnull, ref14 );
executeAction( idUngr, desc24, DialogModes.NO );

 

 

Previous code passed through Clean SL, converted to a function that you can call:

 

 

unGroup();

function unGroup() {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();

	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	executeAction( s2t( "ungroup" ), descriptor, DialogModes.NO );
}

 

 

 

However, you will need to make the layer selection yourself or perhaps somebody else can help there...

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
community guidelines
Adobe Community Professional ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

It was not originally obvious to me, however presuming a selected layer/s:

 

app.runMenuItem( charIDToTypeID("GrpL") );

 

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
community guidelines
Adobe Community Professional ,
May 20, 2020 May 20, 2020

Copy link to clipboard

Copied

OK, try this one:

 

 

/* 
release all clipped layers.jsx

How to release clipped layers:
https://community.adobe.com/t5/photoshop/how-to-release-clipped-layers/td-p/11145702

Credit to:
https://stackoverflow.com/questions/56668542/how-to-identify-clipping-mask-using-javascript-without-ratios-for-photoshop
*/

#target photoshop
app.bringToFront();

function main() {
    var doc = app.activeDocument, layers = doc.layers;

    for (var x = 0; x < layers.length; x++) {
        doc.activeLayer = doc.layers[x];
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var desc = executeActionGet(ref);
        if (desc.hasKey(charIDToTypeID('Grup')) && desc.getBoolean(charIDToTypeID('Grup'))) {
            unGroup();
        }
    }

    function unGroup() {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor(), reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);
        executeAction(s2t("ungroup"), descriptor, DialogModes.NO);
    }
}
app.activeDocument.suspendHistory("Ungroup Layers", "main()");

 

 

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
community guidelines
Contributor ,
May 20, 2020 May 20, 2020

Copy link to clipboard

Copied

Thanks, this works, but this script release all clipped layers on a file. Can I limit this function only on selected layer?

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
community guidelines
Adobe Community Professional ,
May 21, 2020 May 21, 2020

Copy link to clipboard

Copied

You didn't specify that it should only be selected layers, just that the number would be variable... I'll see what I can do, but no promises.

 

EDIT: The previous code that I first posted works on selected layers, however, there are limitations. Can you post a cropped screenshot of the layers panel with the exact layer structure and selected 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
community guidelines
Contributor ,
May 21, 2020 May 21, 2020

Copy link to clipboard

Copied

Ok, below is an example.

P.S. Structure of layers is different case by case, also names of layers are not definded.

Screenshot 2020-05-21 at 1.17.52 PM.png

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
community guidelines
Adobe Community Professional ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

OK, so layer A is selected. What now? Is it that A1/A2/A3 should then be unclipped, while the clipped layers of B and C remain unchanged? What you require is not clear to me...

 

 

// Release clipping layers from base layer
#target photoshop
app.bringToFront();
function main() {
    app.runMenuItem(charIDToTypeID("GrpL"));
    app.runMenuItem(charIDToTypeID("GrpL"));
}
app.activeDocument.suspendHistory("Release clipping layers", "main()");

 

 

 

Presuming that the "base" layer A is selected, the above script will toggle clipping on/off – which has the side effect of releasing clipping on all the layers originally clipped to layer A! 

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
community guidelines
Contributor ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

This work perfectly, sorry if i confused you. Thanks.

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
community guidelines
Adobe Community Professional ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Thank you for marking a correct answer and showing the courtesy of a reply, greatly appreciated!

 

EDIT: I just wanted to post a slightly refined version of the previous script. I did not like calling the same command twice in a row with the same code, it worked, however, I thought that it looked a little ugly... So here is an alternative that is more elegant.

 

 

// Release clipping layers from base layer
#target photoshop
app.bringToFront();
function main() {
    // Repeat x2 times
    for (var i = 0; i < 2; i++) app.runMenuItem(charIDToTypeID("GrpL"));
}
app.activeDocument.suspendHistory("Release clipping layers", "main()");

 

 

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
community guidelines
Explorer ,
Jun 17, 2021 Jun 17, 2021

Copy link to clipboard

Copied

How to  delete  all clipped layer

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
community guidelines
Explorer ,
Jun 17, 2021 Jun 17, 2021

Copy link to clipboard

Copied

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
community guidelines
Adobe Community Professional ,
Jun 17, 2021 Jun 17, 2021

Copy link to clipboard

Copied

Can you post a before and after cropped screenshot of the layers panel?

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
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

var doc = activeDocument,
layers = activeDocument.layers;

for (var x = 0; x < layers.length; x++)
{
doc.activeLayer = doc.layers[x];
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
if (desc.hasKey(charIDToTypeID('Grup')) && desc.getBoolean(charIDToTypeID('Grup')))
{

var idhistoryStateChanged = stringIDToTypeID( "historyStateChanged" );
var desc1480 = new ActionDescriptor();
var idDocI = charIDToTypeID( "DocI" );
desc1480.putInteger( idDocI, 219 );
var idIdnt = charIDToTypeID( "Idnt" );
desc1480.putInteger( idIdnt, 607 );
var idNm = charIDToTypeID( "Nm " );
desc1480.putString( idNm, """Delete Layer""" );
var idhasEnglish = stringIDToTypeID( "hasEnglish" );
desc1480.putBoolean( idhasEnglish, true );
var idDlt = charIDToTypeID( "Dlt " );
var desc1481 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref145 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref145.putEnumerated( idLyr, idOrdn, idTrgt );
desc1481.putReference( idnull, ref145 );
var idLyrI = charIDToTypeID( "LyrI" );
var list63 = new ActionList();
list63.putInteger( 59 );
desc1481.putList( idLyrI, list63 );
executeAction( idDlt, desc1481, 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
community guidelines
Adobe Community Professional ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

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
community guidelines
Explorer ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

How to ignore This layer name (”image x”) and Delete every all clipping layer

This script Delete All Layer 

///////////////////////////////////////////////////////////////////////////////////////

var doc = activeDocument,
layers = activeDocument.layers;

for (var x = 0; x < layers.length; x++)
{
doc.activeLayer = doc.layers[x];
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
if (desc.hasKey(charIDToTypeID('Grup')) && desc.getBoolean(charIDToTypeID('Grup')))
{

var idhistoryStateChanged = stringIDToTypeID( "historyStateChanged" );
var desc1480 = new ActionDescriptor();
var idDocI = charIDToTypeID( "DocI" );
desc1480.putInteger( idDocI, 219 );
var idIdnt = charIDToTypeID( "Idnt" );
desc1480.putInteger( idIdnt, 607 );
var idNm = charIDToTypeID( "Nm " );
desc1480.putString( idNm, """Delete Layer""" );
var idhasEnglish = stringIDToTypeID( "hasEnglish" );
desc1480.putBoolean( idhasEnglish, true );
var idDlt = charIDToTypeID( "Dlt " );
var desc1481 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref145 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref145.putEnumerated( idLyr, idOrdn, idTrgt );
desc1481.putReference( idnull, ref145 );
var idLyrI = charIDToTypeID( "LyrI" );
var list63 = new ActionList();
list63.putInteger( 59 );
desc1481.putList( idLyrI, list63 );
executeAction( idDlt, desc1481, DialogModes.NO );

}
}

 

clipping.jpg

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
community guidelines
Adobe Community Professional ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

lrs = [].slice.call(activeDocument.layers)
while(lrs.length && ((shft = lrs.shift()).grouped
&& shft.name != 'Image X' && shft.remove(), true)){}

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
community guidelines
Explorer ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

thank you very much sir        this script works but finally the error comeserror.jpg

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
community guidelines
Adobe Community Professional ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

That's not part of my script.

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
community guidelines
Explorer ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

yes sr 

but sorry i don't know english 

  this language  google translate

i hope your help help me

there is no problem with your script but there is a problem with my script but i have no solution

 

 

this code

var idNm = charIDToTypeID( "Nm " );

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
community guidelines
Adobe Community Professional ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

Why do you need your script if mine does what you wanted?

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
community guidelines
Explorer ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

i have created a script i am very happy i am creating a droplet clipping mask in psd template which saves the new image and removes the old image psd template thank you so much for giving me the code and wasting your precious time for me i thank you i am happy

 

sorry sir i may have made a mistake in writing english but i will let you know when the script is ready

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
community guidelines
Adobe Community Professional ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

A new topic would be better.

 

Anyway, I believe that your mistake is simple, charID codes are 4 characters, not 3, including blank spaces to pad out to a length of four characters.

 

(charIDToTypeID ("Nm  "))

(stringIDToTypeID ("name"))

 

 

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
community guidelines
Explorer ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

thank you for your reply

thank you for taking me to your attention and helping me and wasting your precious time

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
community guidelines
Adobe Community Professional ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

Correcting that makes his script still useless, so I even didn't suggested that.

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
community guidelines
    • 1
    • 2