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
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
...
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. )
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!
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); }
}
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
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); }
}
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!
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.
Copy link to clipboard
Copied
Hello r-bin,
sorry for the late answer! I tried, and it's not working in my Photoshop.
Thank you for supporting 🙂
Copy link to clipboard
Copied
@Fat Croissant – Please mark the replies that solved your issue as "correct answers", thank you.
Copy link to clipboard
Copied
@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!