Skip to content

layers

Layers

Bases: Photoshop

The layers collection in the document.

Source code in photoshop/api/_layers.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Layers(Photoshop):
    """The layers collection in the document."""

    def __init__(self, parent):
        super().__init__(parent=parent)
        self._flag_as_method(
            "add",
            "item",
        )

    @property
    def _layers(self):
        return list(self.app)

    def __len__(self):
        return self.length

    def __getitem__(self, key):
        item = self._layers[key]
        return ArtLayer(item)

    @property
    def length(self):
        return len(self._layers)

    def removeAll(self):
        """Deletes all elements."""
        for layer in self.app:
            ArtLayer(layer).remove()

    def item(self, index):
        return ArtLayer(self.app.item(index))

    def __iter__(self):
        for layer in self._layers:
            yield ArtLayer(layer)

    def getByName(self, name: str) -> ArtLayer:
        """Get the first element in the collection with the provided name."""
        for layer in self.app:
            if layer.name == name:
                return ArtLayer(layer)
        raise PhotoshopPythonAPIError("X")

getByName(name)

Get the first element in the collection with the provided name.

Source code in photoshop/api/_layers.py
45
46
47
48
49
50
def getByName(self, name: str) -> ArtLayer:
    """Get the first element in the collection with the provided name."""
    for layer in self.app:
        if layer.name == name:
            return ArtLayer(layer)
    raise PhotoshopPythonAPIError("X")

removeAll()

Deletes all elements.

Source code in photoshop/api/_layers.py
33
34
35
36
def removeAll(self):
    """Deletes all elements."""
    for layer in self.app:
        ArtLayer(layer).remove()

Last update: 2024-03-05
Created: 2024-03-05