Skip to content

selection

The selected area of the document or layer.

Selection

Bases: Photoshop

The selected area of the document.

Source code in photoshop/api/_selection.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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
class Selection(Photoshop):
    """The selected area of the document."""

    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._flag_as_method(
            "clear",
            "contract",
            "copy",
            "cut",
            "deselect",
            "expand",
            "feather",
            "fill",
            "grow",
            "invert",
            "load",
            "makeWorkPath",
            "resize",
            "resizeBoundary",
            "rotate",
            "rotateBoundary",
            "select",
            "selectBorder",
            "similar",
            "smooth",
            "store",
            "stroke",
            "translate",
            "translateBoundary",
        )

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

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

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

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

    def clear(self):
        """Clears the selection and does not copy it to the clipboard."""
        self.app.clear()

    def contract(self, contract_by):
        """Contracts the selection."""
        self.app.contract(contract_by)

    def copy(self):
        """Copies the selection to the clipboard."""
        self.app.copy()

    def cut(self):
        """Cuts the current selection to the clipboard."""
        self.app.cut()

    def select(self, *args, **kwargs):
        return self.app.select(*args, **kwargs)

    def deselect(self):
        """Deselects the current selection."""
        return self.app.deselect()

    def expand(self, by: int):
        """Expands the selection.

        Args:
            by: The amount to expand the selection.

        """
        self.app.expand(by)

    def feather(self, by: int):
        """Feathers the edges of the selection.

        Args:
            by: The amount to feather the edge.

        """
        return self.app.feather(by)

    def fill(
        self,
        fill_type: SolidColor,
        mode: ColorBlendMode = None,
        opacity=None,
        preserve_transparency=None,
    ):
        """Fills the selection."""
        return self.app.fill(fill_type, mode, opacity, preserve_transparency)

    def grow(self, tolerance, anti_alias):
        """Grows the selection to include all adjacent pixels falling within

        The specified tolerance range.

        Args:
            tolerance (int): The tolerance range. Range: 0 to 255.
            anti_alias (bool): If true, anti-aliasing is used.


        """
        return self.app.grow(tolerance, anti_alias)

    def invert(self):
        """Inverts the selection."""
        self.app.invert()

    def load(self, from_channel, combination, inverting):
        """Loads the selection from the specified channel."""
        return self.app.load(from_channel, combination, inverting)

    def makeWorkPath(self, tolerance):
        """Makes this selection item the workpath for this document."""
        self.app.makeWorkPath(tolerance)

    def resize(self, horizontal, vertical, anchor):
        """Resizes the selected area to the specified dimensions and anchor
        position."""
        self.app.resize(horizontal, vertical, anchor)

    def resizeBoundary(self, horizontal, vertical, anchor):
        """Scales the boundary of the selection."""
        self.app.resizeBoundary(horizontal, vertical, anchor)

    def rotate(self, angle, anchor):
        """Rotates the object."""
        self.app.rotate(angle, anchor)

    def rotateBoundary(self, angle, anchor):
        """Rotates the boundary of the selection."""
        self.app.rotateBoundary(angle, anchor)

    def stroke(self, strokeColor, width, location, mode, opacity, preserveTransparency):
        """Strokes the selection.

        Args:
            strokeColor (SolidColor): The color to stroke the selection with.
            width (int): The stroke width.
            location (int): The stroke location.
            mode (int): The color blend mode.
            opacity (int): The opacity of the stroke color as a percentage.
                Range: 1 to 100.
            preserveTransparency (bool): If true, preserves transparency.

        """
        return self.app.stroke(strokeColor, width, location, mode, opacity, preserveTransparency)

    def selectBorder(self, width):
        """Selects the selection border only (in the specified width);
        subsequent actions do not affect the selected area within the borders.

        Args:
            width (int): The width of the border selection.

        """
        return self.app.selectBorder(width)

    def similar(self, tolerance, antiAlias):
        return self.app.similar(tolerance, antiAlias)

    def smooth(self, radius):
        """Cleans up stray pixels left inside or outside a color-based
        selection (within the radius specified in pixels)."""
        return self.app.smooth(radius)

    def store(self, into, combination=SelectionType.ReplaceSelection):
        """Saves the selection as a channel."""
        return self.app.store(into, combination)

    def translate(self, deltaX, deltaY):
        """Moves the object relative to its current position."""
        return self.app.translate(deltaX, deltaY)

    def translateBoundary(self, deltaX, deltaY):
        """Moves the boundary of selection relative to its current position."""
        return self.app.translateBoundary(deltaX, deltaY)

clear()

Clears the selection and does not copy it to the clipboard.

Source code in photoshop/api/_selection.py
58
59
60
def clear(self):
    """Clears the selection and does not copy it to the clipboard."""
    self.app.clear()

contract(contract_by)

Contracts the selection.

Source code in photoshop/api/_selection.py
62
63
64
def contract(self, contract_by):
    """Contracts the selection."""
    self.app.contract(contract_by)

copy()

Copies the selection to the clipboard.

Source code in photoshop/api/_selection.py
66
67
68
def copy(self):
    """Copies the selection to the clipboard."""
    self.app.copy()

cut()

Cuts the current selection to the clipboard.

Source code in photoshop/api/_selection.py
70
71
72
def cut(self):
    """Cuts the current selection to the clipboard."""
    self.app.cut()

deselect()

Deselects the current selection.

Source code in photoshop/api/_selection.py
77
78
79
def deselect(self):
    """Deselects the current selection."""
    return self.app.deselect()

expand(by)

Expands the selection.

Parameters:

Name Type Description Default
by int

The amount to expand the selection.

required
Source code in photoshop/api/_selection.py
81
82
83
84
85
86
87
88
def expand(self, by: int):
    """Expands the selection.

    Args:
        by: The amount to expand the selection.

    """
    self.app.expand(by)

feather(by)

Feathers the edges of the selection.

Parameters:

Name Type Description Default
by int

The amount to feather the edge.

required
Source code in photoshop/api/_selection.py
90
91
92
93
94
95
96
97
def feather(self, by: int):
    """Feathers the edges of the selection.

    Args:
        by: The amount to feather the edge.

    """
    return self.app.feather(by)

fill(fill_type, mode=None, opacity=None, preserve_transparency=None)

Fills the selection.

Source code in photoshop/api/_selection.py
 99
100
101
102
103
104
105
106
107
def fill(
    self,
    fill_type: SolidColor,
    mode: ColorBlendMode = None,
    opacity=None,
    preserve_transparency=None,
):
    """Fills the selection."""
    return self.app.fill(fill_type, mode, opacity, preserve_transparency)

grow(tolerance, anti_alias)

Grows the selection to include all adjacent pixels falling within

The specified tolerance range.

Parameters:

Name Type Description Default
tolerance int

The tolerance range. Range: 0 to 255.

required
anti_alias bool

If true, anti-aliasing is used.

required
Source code in photoshop/api/_selection.py
109
110
111
112
113
114
115
116
117
118
119
120
def grow(self, tolerance, anti_alias):
    """Grows the selection to include all adjacent pixels falling within

    The specified tolerance range.

    Args:
        tolerance (int): The tolerance range. Range: 0 to 255.
        anti_alias (bool): If true, anti-aliasing is used.


    """
    return self.app.grow(tolerance, anti_alias)

invert()

Inverts the selection.

Source code in photoshop/api/_selection.py
122
123
124
def invert(self):
    """Inverts the selection."""
    self.app.invert()

load(from_channel, combination, inverting)

Loads the selection from the specified channel.

Source code in photoshop/api/_selection.py
126
127
128
def load(self, from_channel, combination, inverting):
    """Loads the selection from the specified channel."""
    return self.app.load(from_channel, combination, inverting)

makeWorkPath(tolerance)

Makes this selection item the workpath for this document.

Source code in photoshop/api/_selection.py
130
131
132
def makeWorkPath(self, tolerance):
    """Makes this selection item the workpath for this document."""
    self.app.makeWorkPath(tolerance)

resize(horizontal, vertical, anchor)

Resizes the selected area to the specified dimensions and anchor position.

Source code in photoshop/api/_selection.py
134
135
136
137
def resize(self, horizontal, vertical, anchor):
    """Resizes the selected area to the specified dimensions and anchor
    position."""
    self.app.resize(horizontal, vertical, anchor)

resizeBoundary(horizontal, vertical, anchor)

Scales the boundary of the selection.

Source code in photoshop/api/_selection.py
139
140
141
def resizeBoundary(self, horizontal, vertical, anchor):
    """Scales the boundary of the selection."""
    self.app.resizeBoundary(horizontal, vertical, anchor)

rotate(angle, anchor)

Rotates the object.

Source code in photoshop/api/_selection.py
143
144
145
def rotate(self, angle, anchor):
    """Rotates the object."""
    self.app.rotate(angle, anchor)

rotateBoundary(angle, anchor)

Rotates the boundary of the selection.

Source code in photoshop/api/_selection.py
147
148
149
def rotateBoundary(self, angle, anchor):
    """Rotates the boundary of the selection."""
    self.app.rotateBoundary(angle, anchor)

selectBorder(width)

Selects the selection border only (in the specified width); subsequent actions do not affect the selected area within the borders.

Parameters:

Name Type Description Default
width int

The width of the border selection.

required
Source code in photoshop/api/_selection.py
166
167
168
169
170
171
172
173
174
def selectBorder(self, width):
    """Selects the selection border only (in the specified width);
    subsequent actions do not affect the selected area within the borders.

    Args:
        width (int): The width of the border selection.

    """
    return self.app.selectBorder(width)

smooth(radius)

Cleans up stray pixels left inside or outside a color-based selection (within the radius specified in pixels).

Source code in photoshop/api/_selection.py
179
180
181
182
def smooth(self, radius):
    """Cleans up stray pixels left inside or outside a color-based
    selection (within the radius specified in pixels)."""
    return self.app.smooth(radius)

store(into, combination=SelectionType.ReplaceSelection)

Saves the selection as a channel.

Source code in photoshop/api/_selection.py
184
185
186
def store(self, into, combination=SelectionType.ReplaceSelection):
    """Saves the selection as a channel."""
    return self.app.store(into, combination)

stroke(strokeColor, width, location, mode, opacity, preserveTransparency)

Strokes the selection.

Parameters:

Name Type Description Default
strokeColor SolidColor

The color to stroke the selection with.

required
width int

The stroke width.

required
location int

The stroke location.

required
mode int

The color blend mode.

required
opacity int

The opacity of the stroke color as a percentage. Range: 1 to 100.

required
preserveTransparency bool

If true, preserves transparency.

required
Source code in photoshop/api/_selection.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def stroke(self, strokeColor, width, location, mode, opacity, preserveTransparency):
    """Strokes the selection.

    Args:
        strokeColor (SolidColor): The color to stroke the selection with.
        width (int): The stroke width.
        location (int): The stroke location.
        mode (int): The color blend mode.
        opacity (int): The opacity of the stroke color as a percentage.
            Range: 1 to 100.
        preserveTransparency (bool): If true, preserves transparency.

    """
    return self.app.stroke(strokeColor, width, location, mode, opacity, preserveTransparency)

translate(deltaX, deltaY)

Moves the object relative to its current position.

Source code in photoshop/api/_selection.py
188
189
190
def translate(self, deltaX, deltaY):
    """Moves the object relative to its current position."""
    return self.app.translate(deltaX, deltaY)

translateBoundary(deltaX, deltaY)

Moves the boundary of selection relative to its current position.

Source code in photoshop/api/_selection.py
192
193
194
def translateBoundary(self, deltaX, deltaY):
    """Moves the boundary of selection relative to its current position."""
    return self.app.translateBoundary(deltaX, deltaY)

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