How to remove word "copy" from duplicated layers in layerSets

Engaged ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

How to remove word copy from layers, when i duplicate group with script? After using this script all layers in duplicated group got sufix copy, when i duplicate group manualy layers doesnt have this sufix. Thanks in advance

var theDoc = app.activeDocument;
var theLayer = theDoc.activeLayer.duplicate(theDoc.activeLayer, ElementPlacement.PLACEBEFORE);
theLayer.name = "Duplicate";

Screen Shot 2022-08-19 at 14.11.39.png 

TOPICS
Actions and scripting

Views

144

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 3 Correct answers

Community Expert , Aug 19, 2022 Aug 19, 2022

 

var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t("property"), p = s2t("addCopyToLayerNames"));
r.putClass(s2t("application"));
(d = new ActionDescriptor()).putReference(s2t("target"), r);
var addCopy = executeActionGet(r).getBoolean(p);
d.putBoolean(s2t("addCopyToLayerNames"), false)
executeAction(s2t("set"), d, DialogModes.NO);
executeAction(s2t("copyToLayer"), undefined, DialogModes.NO);
d.putBoolean(s2t("addCopyToLayerNames"), addCopy)
executeAction(s2t("set"), d, Dia
...

Likes

Translate

Translate
Community Expert , Aug 19, 2022 Aug 19, 2022

@milevic – Here is another take, it uses a modified function created from the Layer > Duplicate Layer/Group command which includes the layer rename as a parameter in the function call:

 

dupeWithoutCopy("Duplicate");

function dupeWithoutCopy(layerName) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var list = new ActionList();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "ta
...

Likes

Translate

Translate
Community Expert , Aug 20, 2022 Aug 20, 2022

@milevic wrote:

Thanks guys, it works perfect, second one is interesting for me because it changes name of group also


 

Thanks, that is a natural feature of the command... however, you know how to change the parent group name if you use the code from jazz-y. Same with the code from r-bin.

 

As an example, extending the code from jazz-y into a function with a variable and a parameter to rename:

 

dupeWithoutCopy("Duplicate");

function dupeWithoutCopy(theName) {
    var s2t = stringIDToTypeID;
 
...

Likes

Translate

Translate
Community Expert ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

Did you turn off »Add "copy" …« in the Layers Panel Options? 

Screenshot 2022-08-19 at 15.06.47.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
Community Expert ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

@c.pfaffenbichler – This too was my first thought when this came up a week or two ago in another topic. It appears that the DOM code ignores this setting, which of course means that AM code is required.

 

Edit: Looking at that other topic, I came up with the following, however, I can't recall how I extracted that bit of code from SL:

 

// SL code
var idcopyToLayer = stringIDToTypeID( "copyToLayer" );
executeAction(idcopyToLayer, undefined, DialogModes.NO);
// DOM code
activeDocument.activeLayer.name = "Duplicate";

 

Another one here from @r-bin –

 

executeAction( stringIDToTypeID("copyToLayer"), undefined, DialogModes.NO );

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-copy-group-of-layers-withou...

 

Both of these require the layer panel options to be set to not add the word copy for the parent set, however the child layers don't have the word copy, even if the layer panel is set otherwise.

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
Community Expert ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

 

var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t("property"), p = s2t("addCopyToLayerNames"));
r.putClass(s2t("application"));
(d = new ActionDescriptor()).putReference(s2t("target"), r);
var addCopy = executeActionGet(r).getBoolean(p);
d.putBoolean(s2t("addCopyToLayerNames"), false)
executeAction(s2t("set"), d, DialogModes.NO);
executeAction(s2t("copyToLayer"), undefined, DialogModes.NO);
d.putBoolean(s2t("addCopyToLayerNames"), addCopy)
executeAction(s2t("set"), d, 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
Community Expert ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard

Copied

@milevic – Here is another take, it uses a modified function created from the Layer > Duplicate Layer/Group command which includes the layer rename as a parameter in the function call:

 

dupeWithoutCopy("Duplicate");

function dupeWithoutCopy(layerName) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var list = new ActionList();
	var reference = new ActionReference();
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
    descriptor.putReference(s2t("null"), reference);
    // Layer/Group name
	descriptor.putString( s2t( "name" ), layerName );
	descriptor.putInteger( s2t( "version" ), 5 );
	descriptor.putList( s2t( "ID" ), list );
	executeAction( s2t( "duplicate" ), descriptor, DialogModes.NO );
}

 

That being said, I do prefer the script from @jazz-y

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
Engaged ,
Aug 20, 2022 Aug 20, 2022

Copy link to clipboard

Copied

Thanks guys, it works perfect, second one is interesting for me because it changes name of group also

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
Community Expert ,
Aug 20, 2022 Aug 20, 2022

Copy link to clipboard

Copied


@milevic wrote:

Thanks guys, it works perfect, second one is interesting for me because it changes name of group also


 

Thanks, that is a natural feature of the command... however, you know how to change the parent group name if you use the code from jazz-y. Same with the code from r-bin.

 

As an example, extending the code from jazz-y into a function with a variable and a parameter to rename:

 

dupeWithoutCopy("Duplicate");

function dupeWithoutCopy(theName) {
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t("property"), p = s2t("addCopyToLayerNames"));
    r.putClass(s2t("application"));
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    var addCopy = executeActionGet(r).getBoolean(p);
    d.putBoolean(s2t("addCopyToLayerNames"), false)
    executeAction(s2t("set"), d, DialogModes.NO);
    executeAction(s2t("copyToLayer"), undefined, DialogModes.NO);
    d.putBoolean(s2t("addCopyToLayerNames"), addCopy)
    executeAction(s2t("set"), d, DialogModes.NO);
    // Rename the active layer
    activeDocument.activeLayer.name = theName;
}

 

Or, extending the code from r-bin:

 

dupeWithoutCopy("Duplicate");

function dupeWithoutCopy(theName) {
    executeAction(stringIDToTypeID("copyToLayer"), undefined, DialogModes.NO);
    activeDocument.activeLayer.name = theName;
}

 

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
Engaged ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

LATEST

Thanks @Stephen_A_Marsh it works perfectly

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