Duplicate and rename layers

Viewing 5 reply threads
  • Author
    Posts
    • #99060
      Klaas VT
      Member

      I’m working on a script to duplicate a layer in all documents in a book. The script compiles all layers which are common across all documents, then allows the user to select the ones to duplicate. How can I within the script rename the layer copy at the same time?
      Here’s the snippet:

      //if the box is checked
      if (checkList[check].checkedState == true)
      {
      //duplicate checked layer
      docList[d].layers.item (layerList[check]).duplicate()
      //How do I rename the layer which was created?
      //does not work: docList[d].layers.previousItem (layerList[check]).name = “Unpriced”;
      }

      Any pointers?
      Sorry if this is super basic, I’ve jsut started.

    • #99064
      Mike Dean
      Member

      I’m not sure at a glance why the previousItem method isn’t working, but if you assign the duplicate layer to a variable:

      var newLayer = docList[d].layers.item (layerList[check]).duplicate();

      You can then refer to it later:

      newLayer.name = "Unpriced";

    • #99070
      Klaas VT
      Member

      That does it fine….
      Thanks Mike!

    • #99073

      Klaas, you can also rename it while duplicating:

      docList[d].layers.item (layerList[check]).duplicate().name = "Unpriced";
      

      Didn’t have a look at it, but I assume, that previousItem() needs a layer and not a number.

    • #99075

      … or the index is messed up at this time.

    • #99077
      Klaas VT
      Member

      OK, thanks for the help, all questions answered!
      KvT

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
>