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

Shift+Ctrl+Alt+E Stamp Layer script equivalent

Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

A stamp layer is easy via Shift+Ctrl+Alt+E but is pages long in scrptlistener, is there an easy way to scipt this?

TOPICS
Actions and scripting

Views

1.0K

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

LEGEND , Jun 17, 2020 Jun 17, 2020

If you want duplication was selected, use this code after bG.duplicate() (before semicolon):

 

, aD.activeHistoryState = (sH = aD.historyStates)[sH.length - 1]

 

Votes

Translate

Translate
Adobe
Contributor ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

You could try this...

 

 

function stampLayer(){
    var adStampLayer = new ActionDescriptor();
    adStampLayer.putBoolean( charIDToTypeID( "Dplc" ), true );
    executeAction( charIDToTypeID( "MrgV" ), adStampLayer, DialogModes.NO );
};

 

Set the Dplc to false to emulate "Flatten Image", though you can do that in one line by removing adStampLayer and replace it by undefined in executeAction

 

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

many thanks unfortunately i get a message that mrge visible not available in this version of photoshop where there is only 1 layer

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
Contributor ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

With one layer it won't be possible indeed. You could try this alternative...

 

function stampLayer(){
    try {
        var adStampLayer = new ActionDescriptor();
        adStampLayer.putBoolean( charIDToTypeID( "Dplc" ), true );
        executeAction( charIDToTypeID( "MrgV" ), adStampLayer, DialogModes.NO );
    } catch (e){
        $.writeln(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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

I have seeen plenty of scripts over the last few days that check the amount of layers before preceeding as what I need to do is create a copy of the background if there is not multiple layers

So stamp if multiple, copy if one and then name that layer as Blur

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
LEGEND ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

if (!((lrs = (aD = activeDocument).layers).length - 1) && (bG = lrs[0]).isBackgroundLayer) bG.duplicate()

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

Combining the answers and adding a small amount I get this function, it creates the new layer as required, for the stamp layer it does name it as BLUR but for the background only copy it renames the background layer as BLUR and the new layer is Background copy, so I need to get the new layer in focus before the rename action

function stampLayer(){
    if (activeDocument.layers.length > 1){
        var adStampLayer = new ActionDescriptor();
        adStampLayer.putBoolean( charIDToTypeID( "Dplc" ), true );
	executeAction( charIDToTypeID( "MrgV" ), adStampLayer, DialogModes.NO ); }
	
	if (!((lrs = (aD = activeDocument).layers).length - 1) && (bG = lrs[0]).isBackgroundLayer) bG.duplicate();
	
	var docRef = activeDocument
	docRef.activeLayer.name = "BLUR";
	docRef.activeLayer.applyGaussianBlur(20);
    
};

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
LEGEND ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

If you want duplication was selected, use this code after bG.duplicate() (before semicolon):

 

, aD.activeHistoryState = (sH = aD.historyStates)[sH.length - 1]

 

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

Many thanks for the help, final code is

function stampLayer(){
    if (activeDocument.layers.length > 1){
        var adStampLayer = new ActionDescriptor();
        adStampLayer.putBoolean( charIDToTypeID( "Dplc" ), true );
	executeAction( charIDToTypeID( "MrgV" ), adStampLayer, DialogModes.NO ); }
	
	if (!((lrs = (aD = activeDocument).layers).length - 1) && (bG = lrs[0]).isBackgroundLayer) bG.duplicate(), aD.activeHistoryState = (sH = aD.historyStates)[sH.length - 1];
	
	var docRef = activeDocument
	docRef.activeLayer.name = "BLUR";
	docRef.activeLayer.applyGaussianBlur(20);
    
};

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 ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

It will not work if you use the code inside suspendHistory.
 

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

you have lost me with that answer

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
LEGEND ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

I'm aware of that but he is beginner and don't need supsend history yet. Till then he learns how to achive what he wants by more convinient methods where suspendHistory can be used.

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
Contributor ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

If you want it a bit shorter, try this one:

 

function stampLayer(layerName){
    if (activeDocument.layers.length > 1){
        var adStampLayer = new ActionDescriptor();
        adStampLayer.putBoolean( charIDToTypeID( "Dplc" ), true );
	    executeAction( charIDToTypeID( "MrgV" ), adStampLayer, DialogModes.NO ); 
    } else {
        executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO ); 
    }
    app.activeDocument.activeLayer.name = layerName;
}

stampLayer("yourName (BLUR)");
app.activeDocument.activeLayer.applyGaussianBlur(20);

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

so I would need to add 

var layerName = 'BLUR';
stampLayer (layerName);

to use that if I am reading it correctly? 

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 ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

From the Kukurykus code you can get to a mental hospital (just kidding: ).
This is definitely not for beginners.
Here, try it.
app.activeDocument.artLayers.add();
app.activeDocument.activeLayer.name = "BLUR";

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

app.activeDocument.activeLayer.applyGaussianBlur(20);

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
LEGEND ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

That's not my code but his. I didn't write it from beginning but only updated of that he wanted.

And I didn't say that code is for beginners, but only he is beginner so doesn't use everything yet.

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
Participant ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

I totally appreciate the elegant solution r-bin as much as I appreciate all the help that Kukurykus has given me over the last week. I am not new to coding, been doing bits and pieces over 40 years out of necessity mostly but very new to Photoshop Javascript - I was taught that first priority is to get it working and then if time allows make it elegant.

Bound to be issues or new things to try so many thanks to all the community and maybe someone else will benefit from my questions

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 ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

A bit late to the party... I'm a beginner, so take from this what you will... Here is a basic conditional check for a background or layered file.

 

 

if (app.activeDocument.activeLayer.isBackgroundLayer)
	{
	alert("Flattened");
	}
else
	{
	alert("Layered");
	}

 

 

That being said, I'm not sure why you wish to put in this check?

 

The code being discussed will add a new layer, then merge visible layers with duplicate.

 

In my limited testing, the code works the same whether or not the image is flattened or layered. Am I missing something?

 

P.S. I would have offered this code for the new layer/merge visible with dupe:

 

app.activeDocument.artLayers.add();
var mrgVis = charIDToTypeID("MrgV");
var actDesc = new ActionDescriptor();
var withDupe = charIDToTypeID("Dplc");
actDesc.putBoolean(withDupe, true);
executeAction(mrgVis, actDesc, DialogModes.NO);

 

 

 

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
Participant ,
Jun 18, 2020 Jun 18, 2020

Copy link to clipboard

Copied

LATEST

yes, the original answer I was given threw an error on a single layer document, hence the original need for a 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
LEGEND ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

if (activeDocument.layers.length > 1) {/**do your code/}

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