How to determine whether a artLayer is a layer or a layer group
Describe the bug
We know that app.activeDocument.layers usually represent a collection of layers and layerSets
How do I know if the current layer is a layerSet when I traverse app.activeDocument.layers
To Reproduce Steps to reproduce the behavior: In fact, using JavaScript directly can easily achieve this, but how can I use the Photoshop Python API to do it JavaScript example:
var layers = app.activeDocument.layers;
if (layers[1].typename == "LayerSet"){
alert("this is layer group")
} else {
alert("this is layer")
}
but, in photoshop-python-api, Typename is not a meta attribute of layer, but a fixed class name
# my demo
import photoshop.api as ps
app = ps.Application()
doc = app.activeDocument
for layer in doc.layers:
print(layer.typename)
# in photoshop\api\_core.py L108
@property
def typename(self) -> str:
"""str: Current typename."""
return self.__class__.__name__
I tried to use layer.app.typename to get the typename in the metadata of the layer, but got nothing. How can I determine if the layer is actually a layer group
this is bad example
import photoshop.api as ps
app = ps.Application()
doc = app.activeDocument
for layer in doc.layers:
print(layer.app.typename)
Expected behavior As stated in the title
Screenshots
my screenshots:
Desktop (please complete the following information):
- OS: Windows11
- Photoshop Version: Photoshop-2022
- Python Version: python3.8
I think I know how to judge now
active_document = self.app.activeDocument
layer_group_id_list = []
layer_group_list = active_document.layerSets
for layer_group in layer_group_list:
layer_group_id_list.append(layer_group.id)
layer_list = active_document.layers
for layer in layer_list:
if layer.app.id in layer_group_id_list:
print("this is layer group")
else:
print("this is layer")
But I still have one questions
# photoshop\api\_layers.py L41
def __iter__(self):
for layer in self._layers:
yield ArtLayer(layer)
# photoshop\api\_layerSets.py L24
def __iter__(self):
for layer_set in self.app:
yield layer_set
Why isn't the COM object instantiated in layerset
https://github.com/loonghao/photoshop-python-api/issues/358#issuecomment-2809206355
same problemοΌ π
@gucheng599 @loonghao
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
https://github.com/loonghao/photoshop-python-api/issues/358#issuecomment-2809206355
same problemοΌ π
@gucheng599 @loonghao