Copy link to clipboard
Copied
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?
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.getByNam
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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'),ElementPlacement.PLACEBEFORE);
app.activeDocument.activeLayer.name = 'new top';