質問

I'm trying to figure out if it is something wrong with me or the CS5 JavaScript engine. My Photoshop document have one layer called "A" and a Layer Group called "Group 1".

Consider this example:

var Mess = "";
var Layers = app.activeDocument.layers;
alert(Layers.length);
for (n=0; n<app.activeDocument.layers.length; n++) {
  Mess = Mess + app.activeDocument.layers[n].name + "\r\n";
}
alert(Mess);

This will show 2 for length and then list the layers:
A
Group 1

Everything fine so far. But if we in the foor loop use the variable Layers instead we get a different result.

var Mess = "";
var Layers = app.activeDocument.layers;
alert(Layers.length);
for (n=0; n<Layers.length; n++) {
  Mess = Mess + app.activeDocument.layers[n].name + "\r\n";
}
alert(Mess);

As before we get length 2 but now only one layer is listed:
A

Shouldn't the two code examples produce the same result?!?

役に立ちましたか?

解決

I think Layers is a reserved word in the Photoshop DOM. Photoshop CS6 JavaScript Reference

var Mess = "";
var lyrs = app.activeDocument.layers;
alert(lyrs.length);
for (n=0; n<lyrs.length; n++) {
    Mess = Mess + app.activeDocument.layers[n].name + "\r\n";
}
alert(Mess);

This seems to work now after changing the name of the variable.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top