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

Script for stamping the current and below layers

Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

Hello Hello,

 

I am a total beginner in the field of scripting; so I ask and hope someone might help me out: Is there a script which stamps the current (selected) layer and all visible Layers below into a new Layer above the selected one?

 

(The "standard" Command "Shift - Alt - command - E" creates a Layer with all visible Layers below and above...)

 

I search for this kind of script for quite a time and didn't find it anyway.

Thanks a lot ,

Flo

 

 

 

 

TOPICS
Actions and scripting

Views

425

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

People's Champ , Jan 17, 2023 Jan 17, 2023

Try it.

 

var d = new ActionDescriptor();
var r = new ActionReference();
r.putIdentifier(stringIDToTypeID("layer"), activeDocument.layers[activeDocument.layers.length-1].id);
d.putReference(stringIDToTypeID("null"), r);
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
d.putBoolean(stringIDToTypeID("makeVisible"), false);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

var d = new ActionD
...

Votes

Translate

Translate
Adobe
People's Champ ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

Try it.

 

var d = new ActionDescriptor();
var r = new ActionReference();
r.putIdentifier(stringIDToTypeID("layer"), activeDocument.layers[activeDocument.layers.length-1].id);
d.putReference(stringIDToTypeID("null"), r);
d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
d.putBoolean(stringIDToTypeID("makeVisible"), false);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

var d = new ActionDescriptor();
d.putBoolean(stringIDToTypeID("duplicate"), true);
executeAction(stringIDToTypeID("mergeLayers"), d, DialogModes.NO);

 

 

Restrictions: does not work in CS6, should not have a Background layer.

Anyone can improve. )

Votes

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

Copy link to clipboard

Copied

Thank you very much! 

So far it works super nice 😉 (even with groups under the selected Layer!)

 

What do I have to do to make it work with an Background layer?

 

 

Thank s a lot so far!

Votes

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
People's Champ ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

activeDocument.suspendHistory("Stamp layers below", "f()"); 

function f()
    {
    try
        {
        var last_layer = activeDocument.layers[activeDocument.layers.length-1]; 
        var has_background = last_layer.isBackgroundLayer;

        if (has_background) last_layer.isBackgroundLayer = false; 

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), last_layer.id);
        d.putReference(stringIDToTypeID("null"), r);
        d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelectionContinuous"));
        d.putBoolean(stringIDToTypeID("makeVisible"), false);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

        var d = new ActionDescriptor();
        d.putBoolean(stringIDToTypeID("duplicate"), true);
        executeAction(stringIDToTypeID("mergeLayers"), d, DialogModes.NO);

        if (has_background) last_layer.isBackgroundLayer = true; 
        }
    catch (e) { alert(e); }
    }

Votes

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 ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Dear @r-bin ,

 

I wanna say thank you! Your script helps me a lot!
If I might ask you one more favour: If under the top Layer is a group (or more), after making a new Layer on Top all groups are opened. Is there any way to avoid this?

Thank you so much,

Florian

 

 

Votes

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
People's Champ ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Strange behavior. This is a bug or a feature. )

 

Try this script. It may be slower to work if there are many layers (or folders) of the first level of nesting.

 

activeDocument.suspendHistory("Stamp layers below", "f()"); 

function f()
    {
    try
        {
        var len = activeDocument.layers.length; 

        var act_layer = activeDocument.activeLayer; 

        var last_layer = activeDocument.layers[len-1]; 
        var has_background = last_layer.isBackgroundLayer;

        if (has_background) last_layer.isBackgroundLayer = false; 

        for (var i = 0; i < len; i++)
            {
            if (activeDocument.layers[i] != act_layer) continue; 

            for (var n = i+1; n < len; n++)
                {
                var d = new ActionDescriptor();
                var r = new ActionReference();
                r.putIdentifier(stringIDToTypeID("layer"), activeDocument.layers[n].id);
                d.putReference(stringIDToTypeID("null"), r);
                d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
                d.putBoolean(stringIDToTypeID("makeVisible"), false);
                executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
                }

            break;
            }

        var d = new ActionDescriptor();
        d.putBoolean(stringIDToTypeID("duplicate"), true);
        executeAction(stringIDToTypeID("mergeLayers"), d, DialogModes.NO);

        if (has_background) last_layer.isBackgroundLayer = true; 
        }
    catch (e) { alert(e); }
    }

 

 

Votes

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 ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Hi! 

Thank you so much!

Somehow it works; but not always. Sometimes nothing happens.

Intersting...

 

But thank you very much for your support and help!

 

 

 

Votes

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
People's Champ ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Can you reproduce the issue stably?

 

Replace line

 

 

if (activeDocument.layers[i] != act_layer) continue; 

 

 

with

 

 

if (activeDocument.layers[i].id != act_layer.id) continue; 

 

 

and check.

 

Votes

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 ,
Jan 28, 2023 Jan 28, 2023

Copy link to clipboard

Copied

LATEST

Hello r-bin,

sorry for the late answer! I tried, and it's not working in my Photoshop. 

Thank you for supporting 🙂

 

 

Votes

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
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

@Fat Croissant – Please mark the replies that solved your issue as "correct answers", thank you.

Votes

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

Copy link to clipboard

Copied

quote

@Fat Croissant – Please mark the replies that solved your issue as "correct answers", thank you.


By @Stephen_A_Marsh

Hi Stephen; 

Sure! in a moment.

 

Because now all works fine; but the new layer has "(reduziert)" in its layername. Can I turn this somehow off?!

Thank you so much for your help r-bin!

 

 

Votes

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