Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Script to copy Group of layers without adding word "copy"

$
0
0

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[i] == target[match]) {  match++;  pos = i;  }  i++;  }

Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>