3 Replies Latest reply on Dec 11, 2013 5:31 AM by Michael L Hale

    how get Layer ID from Layer Name ?

    Andy_Bat1 Level 1

      Hello everyone.

      Tangled with the implementation of a small script.

      I want to add to each of the selected layers of the Document a new layer with the image, make sure the top of each layer.

      I think what I need:

      1. Create an array of user-selected layers (necessarily by name)

      2. Select image;

      3. Pass through the array to create a layer, put in the new layer selected image and move the array over this layer.

      Found an example where the array is created on indexes, but in my case it's not that - after each addition of a new layer indexes is changes .How do I get the index of the layer by its name?

        • 1. Re: how get Layer ID from Layer Name ?
          Michael L Hale Level 5

          Would need to know if you are using the DOM or Action Manager before I can post an example. The DOM doesn't have a layerID and layerID is not the same as the layer index. The index can change as you noted but the ID doesn't. If you are using Action Manager I would use the layerID.

          • 2. Re: how get Layer ID from Layer Name ?
            Andy_Bat1 Level 1

            I like to work with the DOM. How to move the layer to the house to a certain position?

            I have an example - place layer before background:

             

            app.activeDocument.activeLayer.move(activeDocument.layers[activeDocument.layers.length-1], ElementPlacement.PLACEBEFORE);

             

            but as I understand, I need to know the ID or Index of the layer?

             

            Message was edited by: Andy_Bat1

            • 3. Re: how get Layer ID from Layer Name ?
              Michael L Hale Level 5

              Andy_Bat1 wrote:

              but as I understand, I need to know the ID or Index of the layer?

              No, you need a layer( or layerSet ) object. You can make a reference to a layer object in several ways. The snippet you posted has two, one is the activeLayer property and the second is by index. You can also make a reference using the layer name and some methods like ArtLayers.add() return a layer object. The DOM doesn't have a layer ID property.

               

              app.activeDocument.activeLayer.move(activeDocument.artLayers.getByName('top'),ElementPlace ment.PLACEBEFORE);

              app.activeDocument.activeLayer.name = 'new top';