Skip to content

layerSets

LayerSets

Bases: Photoshop

The layer sets collection in the document.

Source code in photoshop/api/_layerSets.py
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
51
52
53
54
55
56
57
58
59
60
61
62
class LayerSets(Photoshop):
    """The layer sets collection in the document."""

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

    def __len__(self):
        return self.length

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

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

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

    @property
    def length(self) -> int:
        """Number of elements in the collection."""
        return len(self._layerSets)

    def add(self):
        return LayerSet(self.app.add())

    def item(self, index: int) -> LayerSet:
        return LayerSet(self.app.item(index))

    def removeAll(self):
        self.app.removeAll()

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

    def getByName(self, name: str) -> LayerSet:
        """Get the first element in the collection with the provided name."""
        for layer in self.app:
            if name == layer.name:
                return LayerSet(layer)
        raise PhotoshopPythonAPIError(f'Could not find a LayerSet named "{name}"')

length: int property

Number of elements in the collection.

__getitem__(key)

Access a given LayerSet using dictionary key lookup.

Source code in photoshop/api/_layerSets.py
28
29
30
31
32
33
def __getitem__(self, key: str):
    """Access a given LayerSet using dictionary key lookup."""
    try:
        return LayerSet(self.app[key])
    except ArgumentError:
        raise PhotoshopPythonAPIError(f'Could not find a LayerSet named "{key}"')

getByIndex(index)

Access LayerSet using list index lookup.

Source code in photoshop/api/_layerSets.py
53
54
55
def getByIndex(self, index: int):
    """Access LayerSet using list index lookup."""
    return LayerSet(self._layerSets[index])

getByName(name)

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

Source code in photoshop/api/_layerSets.py
57
58
59
60
61
62
def getByName(self, name: str) -> LayerSet:
    """Get the first element in the collection with the provided name."""
    for layer in self.app:
        if name == layer.name:
            return LayerSet(layer)
    raise PhotoshopPythonAPIError(f'Could not find a LayerSet named "{name}"')

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