简体   繁体   English

Photoshop Javascript 到 go 到下一层(上一层)

[英]Photoshop Javascript to go to the next layer (layer above)

I want to be able to go to the layer above.我希望能够 go 到上面的层。 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.我有超过 3000 个文件需要 select 上一层,但我似乎不知道该怎么做。

It always has a different name too.它也总是有不同的名字。 But i always start from the same layer and it's always in the same position.但我总是从同一层开始,它总是在同一个 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.我已经有一段时间了,但我的 Javascript 知识有限。

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.您基本上可以通过其itemIndex属性来判断图层的 z 位置。 So once you have that you can search the one with an itemIndex which is one higher than the current one.因此,一旦你有了它,你就可以搜索一个 itemIndex 比当前高一的。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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