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

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

New Here ,
Dec 08, 2017 Dec 08, 2017

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++;

  }

TOPICS
Actions and scripting
2.5K
Translate
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

People's Champ , Dec 08, 2017 Dec 08, 2017

// takes into account not add "copy" at the end of layer's name

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

Translate
Adobe
Community Expert ,
Dec 08, 2017 Dec 08, 2017

Hi

I've moved your post to the Photoshop Scripting forum where you are more likely to get help with your issue

Dave

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

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

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

// takes into account not add "copy" at the end of layer's name

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

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

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

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

For layers, sometimes you need to do

app.activeDocument.selection.deselect ();

)

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

Layers panel > flyout menu > panel options > last checkbox

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

Too bad it's not scriptable or it is?

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

I don't know. It doesn't looks scriptable. Only thumbnail size in aplication class could be scriptable.

I found these stringIDs

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

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?

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

Here is ID for settings

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

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.

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

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);

Translate
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 ,
Dec 08, 2017 Dec 08, 2017

It gives error. Is it theoretical code or there is some mistake, or maybe it's not possible in CS6 extended to make it?

Translate
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
Enthusiast ,
Dec 08, 2017 Dec 08, 2017

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.

Translate
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 ,
Dec 08, 2017 Dec 08, 2017
LATEST

Well no matter then, reading value gives error as well in CS6

Translate
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