Hey everyone,
I am trying to make a script that will count the number of visible layerSets in a document. I thought it would be something like below, but it keeps returning 1 regardless of how many layerSets are showing.
for (i = 0; i < activeDocument.layerSets.length.visible = true; i++) {
}
alert (i);
Thanks!
Count visible layerSets (warning: total newb)
-
Mike Hale
Count visible layerSets (warning: total newb)
You have both a common javascript error and a Photoshop Object Model error in your code.
activeDocument.layerSets.length is a property of the layerSets collection and returns a Number. Numbers don't have a visible property.
But you can extend object in javascript so your code adds a new property visible and sets it to true. As a side note you use == or === for equates and = to assign.
var count = 0;
for (i = 0; i < activeDocument.layerSets.length; i++) {
if(activeDocument.layerSets[1].visible == true) count++;
}
alert (count);
Note that will only count the visible top level layerSets. It will not count any nested layerSets. To count all the possible layerSets in a document you can either make a recursive function or use Action Manager.
activeDocument.layerSets.length is a property of the layerSets collection and returns a Number. Numbers don't have a visible property.
But you can extend object in javascript so your code adds a new property visible and sets it to true. As a side note you use == or === for equates and = to assign.
var count = 0;
for (i = 0; i < activeDocument.layerSets.length; i++) {
if(activeDocument.layerSets[1].visible == true) count++;
}
alert (count);
Note that will only count the visible top level layerSets. It will not count any nested layerSets. To count all the possible layerSets in a document you can either make a recursive function or use Action Manager.
-
applezap
Count visible layerSets (warning: total newb)
Mike Hale wrote:You have both a common javascript error and a Photoshop Object Model error in your code.
activeDocument.layerSets.length is a property of the layerSets collection and returns a Number. Numbers don't have a visible property.
But you can extend object in javascript so your code adds a new property visible and sets it to true. As a side note you use == or === for equates and = to assign.
var count = 0;
for (i = 0; i < activeDocument.layerSets.length; i++) {
if(activeDocument.layerSets[1].visible == true) count++;
}
alert (count);
Note that will only count the visible top level layerSets. It will not count any nested layerSets. To count all the possible layerSets in a document you can either make a recursive function or use Action Manager.
I changed the [1] after layerSets to and it worked perfectly. Thanks very much!
activeDocument.layerSets.length is a property of the layerSets collection and returns a Number. Numbers don't have a visible property.
But you can extend object in javascript so your code adds a new property visible and sets it to true. As a side note you use == or === for equates and = to assign.
var count = 0;
for (i = 0; i < activeDocument.layerSets.length; i++) {
if(activeDocument.layerSets[1].visible == true) count++;
}
alert (count);
Note that will only count the visible top level layerSets. It will not count any nested layerSets. To count all the possible layerSets in a document you can either make a recursive function or use Action Manager.
I changed the [1] after layerSets to and it worked perfectly. Thanks very much!
-
Mike Hale
Count visible layerSets (warning: total newb)
Yeah, it should have been an i. Typos are something else to add to the list of 'why things don't work'.