Copy link to clipboard
Copied
When you make a copy of a group using duplicate(), the word "copy" is added at the end of every layer inside the group and its subgroups. Is it possible to make duplicate() not add "copy" at the end of layer's name. Disabling "Add copy to copied Layers and Groups" in layer panel settings doesn't affect the running of script.
I came up with recursive solution that removes copy from name, but it runs extremely slow on a large file with hundreds of layers. Are there more elegant solutions.
Structure before duplicating:
+Group1
+Subgroup
-Layer1
-Layer2
Structure after duplicating:
+Group1 copy
+Subgroup copy
-Layer1 copy
-Layer2 copy
+Group1
+Subgroup
-Layer1
-Layer2
var original = app.activeDocument.layerSets.getByName("group1");
app.activeDocument.activeLayer = original;
var copy = source.duplicate();
recFixName(copy);
// Recursively removes copy from name
function recFixName(curr) {
var str = curr.name;
var target = "copy";
var match = 0;
var pos = 0;
var i = 0;
while(i < str.length) {
if(str == target[match]) {
match++;
pos = i;
}
i++;
}
// takes into account not add "copy" at the end of layer's name
executeAction( stringIDToTypeID("copyToLayer"), undefined, DialogModes.NO );
Copy link to clipboard
Copied
Hi
I've moved your post to the Photoshop Scripting forum where you are more likely to get help with your issue
Dave
Copy link to clipboard
Copied
I didn't test it for all cases but that's only workaround what came to me now:
aD = activeDocument, doc = documents.add(), activeDocument = aD
function dpl(v1, v2) {
v1.layerSets[0].duplicate(v2, ElementPlacement.PLACEATEND)
}
dpl(aD, doc), dpl(activeDocument = doc, aD)
doc.close(SaveOptions.DONOTSAVECHANGES)
You may also check recent topic about alike problem: Help With Ps Script: Copy Group to a New PSD
Copy link to clipboard
Copied
// takes into account not add "copy" at the end of layer's name
executeAction( stringIDToTypeID("copyToLayer"), undefined, DialogModes.NO );
Copy link to clipboard
Copied
Ah right, only not add 'copy' at end of duplicated layers. Hah, I did with SL the same, but then noticed there is copy in name of new layerSet, but forgot it may be so as he wants only copy wasn't part of new layers. Anyway, if you want completely same name versions both for layerSets and layers you can use that workaround
Copy link to clipboard
Copied
For layers, sometimes you need to do
app.activeDocument.selection.deselect ();
)
Copy link to clipboard
Copied
Layers panel > flyout menu > panel options > last checkbox
Copy link to clipboard
Copied
Too bad it's not scriptable or it is?
Copy link to clipboard
Copied
I don't know. It doesn't looks scriptable. Only thumbnail size in aplication class could be scriptable.
I found these stringIDs
LyrO | layerOptions | 1283027535 |
LyrP | layersPaletteOptions | 1283027536 |
Copy link to clipboard
Copied
Yes I see them too now between other id's. It's not priority to change thumbanil size by scripting however maybe someone can show an example how that could be done? Anyone?
Copy link to clipboard
Copied
Here is ID for settings
addCopyToLayerNames | dynamicaly generated number |
Copy link to clipboard
Copied
This is from spaces-adapter
/**
* PlayObject to set "add 'copy' to duplicated layer names" preference
*
* @param {boolean} add If true, duplicated layers will have "[layer name] copy" as their name
* @return {PlayObject}
*/
export function setAddCopyToLayerNames (add) {
return new PlayObject("set", {
"null": {
_ref: [
{
_ref: null,
_property: "addCopyToLayerNames"
},
referenceBy.current
]
},
"addCopyToLayerNames": add || false
});
}
So it is possible to set this property. We just need to translate this into AM code.
Copy link to clipboard
Copied
here it is:
function setAddCopyToLayerNames (add){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "addCopyToLayerNames" ) );
ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean(stringIDToTypeID( "addCopyToLayerNames" ), add)
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
}
setAddCopyToLayerNames (false);
Copy link to clipboard
Copied
It gives error. Is it theoretical code or there is some mistake, or maybe it's not possible in CS6 extended to make it?
Copy link to clipboard
Copied
Here is reading value
getAddCopyToLayerNames ();
function getAddCopyToLayerNames (){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "addCopyToLayerNames" ) );
ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var result = executeActionGet(ref).getBoolean(stringIDToTypeID( "addCopyToLayerNames" ));
alert(result);
}
Both works for me in CC2018
CS6 is very old. A lot of things are not working here.
Copy link to clipboard
Copied
Well no matter then, reading value gives error as well in CS6
Find more inspiration, events, and resources on the new Adobe Community
Explore Now