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";
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
...
@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
...
@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;
...
Copy link to clipboard
Copied
Did you turn off »Add "copy" …« in the Layers Panel Options?
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 );
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.
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);
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
Copy link to clipboard
Copied
Thanks guys, it works perfect, second one is interesting for me because it changes name of group also
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;
}
Copy link to clipboard
Copied
Thanks @Stephen_A_Marsh it works perfectly