Finding the top level Layerset using Javascript
My current code is terrible, it's a Friday afternoon special:
if(layer.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
else if(layer.parent.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
else if(layer.parent.parent.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
else if(layer.parent.parent.parent.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
else if(layer.parent.parent.parent.parent.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
else if(layer.parent.parent.parent.parent.parent.parent == doc && isLayerSet) {
//do something in this case fileNew.write('foo');
}
I did this as a proof of concept to see if the rest of the script works (which it does).
The aim of the game for layer i want to get the name of it's top level parent (i.e. the first child of the document).
I know there is an easier way of doing this however I'm still quite new at this and I'm not sure on some of the nuances of both javascript and photoshop so any help would be massively appreciated!
