Skip to content

artlayers

ArtLayers

Bases: Photoshop

The collection of art layer objects in the document.

Source code in photoshop/api/_artlayers.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class ArtLayers(Photoshop):
    """The collection of art layer objects in the document."""

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

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

    def __len__(self):
        return self.length

    def __iter__(self):
        for layer in self.app:
            yield layer

    def __getitem__(self, key: str):
        """Access a given ArtLayer using dictionary key lookup."""
        try:
            return ArtLayer(self.app[key])
        except ArgumentError:
            raise PhotoshopPythonAPIError(f'Could not find an artLayer named "{key}"')

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

    @property
    def parent(self):
        return self.app.parent

    @property
    def typename(self):
        return self.app.typename

    def add(self):
        """Adds an element."""
        return ArtLayer(self.app.add())

    def getByIndex(self, index: int):
        """Access ArtLayer using list index lookup."""
        return ArtLayer(self._layers[index])

    def getByName(self, name: str) -> ArtLayer:
        """Get the first element in the collection with the provided name.

        Raises:
            PhotoshopPythonAPIError: Could not find a artLayer.
        """
        for layer in self.app:
            if layer.name == name:
                return ArtLayer(layer)
        raise PhotoshopPythonAPIError(f'Could not find an artLayer named "{name}"')

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

__getitem__(key)

Access a given ArtLayer using dictionary key lookup.

Source code in photoshop/api/_artlayers.py
31
32
33
34
35
36
def __getitem__(self, key: str):
    """Access a given ArtLayer using dictionary key lookup."""
    try:
        return ArtLayer(self.app[key])
    except ArgumentError:
        raise PhotoshopPythonAPIError(f'Could not find an artLayer named "{key}"')

add()

Adds an element.

Source code in photoshop/api/_artlayers.py
50
51
52
def add(self):
    """Adds an element."""
    return ArtLayer(self.app.add())

getByIndex(index)

Access ArtLayer using list index lookup.

Source code in photoshop/api/_artlayers.py
54
55
56
def getByIndex(self, index: int):
    """Access ArtLayer using list index lookup."""
    return ArtLayer(self._layers[index])

getByName(name)

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

Raises:

Type Description
PhotoshopPythonAPIError

Could not find a artLayer.

Source code in photoshop/api/_artlayers.py
58
59
60
61
62
63
64
65
66
67
def getByName(self, name: str) -> ArtLayer:
    """Get the first element in the collection with the provided name.

    Raises:
        PhotoshopPythonAPIError: Could not find a artLayer.
    """
    for layer in self.app:
        if layer.name == name:
            return ArtLayer(layer)
    raise PhotoshopPythonAPIError(f'Could not find an artLayer named "{name}"')

removeAll()

Deletes all elements.

Source code in photoshop/api/_artlayers.py
69
70
71
72
def removeAll(self):
    """Deletes all elements."""
    for layer in self.app:
        ArtLayer(layer).remove()

Last update: 2024-11-17
Created: 2024-11-17