简体   繁体   中英

Photoshop Javascript to go to the next layer (layer above)

I want to be able to go to the layer above. I have over 3000 files that i need to select the layer above from and I cannot seem to work out how to do it.

It always has a different name too. But i always start from the same layer and it's always in the same position.

I need this to get the contents of a text layer.

Any ideas? I've been at it a while now but my Javascript knowledge is limited.

Thanks

There might be a smarter way to do this, but the following should work. You can basically tell the layer's z-position by its itemIndex property. So once you have that you can search the one with an itemIndex which is one higher than the current one. When you found it, you can make sure it's a text layer and if so, retrieve it's text contents.

var textContent = "";
var doc = app.activeDocument;

var ix = doc.activeLayer.itemIndex;

for(var i = 0; i < doc.layers.length; i++) {

  if(doc.layers[i].itemIndex === ix + 1 && doc.layers[i].kind === LayerKind.TEXT) {
    textContent = doc.layers[i].textItem.contents;
    break;
  }

}

alert("The text content is: " + textContent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM