Edit in GitHubLog an issue

Selection

Represents a selected area or areas in the document. If there is no active selection, the bounds will return null. The selection is pixel-based, though 8-bit transparency is possible.

Pixel selection targets where pixel filters are applied, or from where the histogram measurement is sourced.

Copied to your clipboard
const { app, constants } = require("photoshop");
const doc = app.activeDocument;
await doc.selection.selectRectangle(
{top: 50, left: 50, bottom: 100, right: 100},
constants.SelectionType.REPLACE
);
doc.selection.bounds; // {{top: 50, left: 50, bottom: 100, right: 100}
doc.selection.solid; // true
await doc.selection.selectEllipse(
{top: 50, left: 70, bottom: 140, right: 100},
constants.SelectionType.EXTEND
);
doc.selection.bounds; // {top: 50, left: 50, bottom: 140, right: 100}
doc.selection.solid; // false

Pixel selection while in Quick Mask Mode: When a user switches into Quick Mask Mode, the selection is temporarily shown as a channel instead of the "marching ants" border. While in Quick Mask Mode, new pixel selections can be made via Scripting. However, upon exiting Quick Mask Mode, the Quick Mask Channel will become the active selection.

Properties

NameTypeAccessMin VersionDescription
bounds
R
25.0
The bounding rectangle of the entire selection. It can exceed the bounds of the canvas.
docId
number
R
25.0
The ID of the document of this Selection.
parent
R
25.0
Owner document of this Selection.
solid
boolean
R
25.0
True if the selection itself is a rectangle with all fully selected pixels. Viewed as a channel, for example via Quick Mask Mode, the selection will appear as a completely white rectangle. In that way, it is solid within its bounds.
typename
string
R
25.0
The class name of the referenced object: "Selection".

Methods

contract

25.0

async : Promise<void>

Contract (shrink) the selection by the specified amount.

If the contraction amount is greater than the selected area radius, the selected area will disappear entirely. If there are no other active selected areas, then there will be no active selection altogether.

Copied to your clipboard
await doc.selection.contract(8);

UI Location: Select > Modify > Contract

Parameters

NameTypeDefault valueDescription
by
number
-
The amount to contract the selection (integer in the range 1..500).
applyEffectAtCanvasBounds
boolean
false
By default this is false, meaning that any part of the selection that touches the bounds of the canvas will not be affected by the contraction.

deselect

25.0

async : Promise<void>

Cancel the current selection. The bounds value will then be null.

Copied to your clipboard
await doc.selection.deselect();

UI Location: Select > Deselect


expand

25.0

async : Promise<void>

Expand the selection by the specified amount.

Copied to your clipboard
await doc.selection.expand(42);

UI Location: Select > Modify > Expand

Parameters

NameTypeDefault valueDescription
by
number
-
The amount to expand the selection (integer in the range 1..500).
applyEffectAtCanvasBounds
boolean
false
By default this is false, meaning that any part of the selection that touches the bounds of the canvas will not be affected by the expansion.

feather

25.0

async : Promise<void>

Feather the edges of the selection by the specified amount. This softening of the selection strength is best viewed as a channel via Quick Mask Mode. Large values might make the selection disappear entirely (.bounds would return null).

Copied to your clipboard
await doc.selection.feather(16);

UI Location: Select > Modify > Feather

Parameters

NameTypeDefault valueDescription
by
number
-
The amount to feather the selection with (integer in the range 0.1..1000).
applyEffectAtCanvasBounds
boolean
false
By default this is false, meaning that any part of the selection that touches the bounds of the canvas will not be affected by the feathering.

grow

25.0

async : Promise<void>

Grow the selection to include all adjacent pixels falling within the specified tolerance range.

Copied to your clipboard
await doc.selection.grow(32);

Unsupported modes: Bitmap, RGB 32 bits, Grayscale 32 bits

UI Location: Select > Grow

Parameters

NameTypeDefault valueDescription
tolerance
number
-
The tolerance range (integer in the range 0..255)
antiAlias
boolean
true
Whether to use anti-aliasing

inverse

25.0

async : Promise<void>

Set the active selection to the inverse of the current selection. The new active selection will be cropped to the canvas bounds. If the canvas area is fully selected, inverse will result in no active selection. Note also that Artboard bounds are not respected.

Copied to your clipboard
await doc.selection.inverse();

UI Location: Select > Inverse


load

25.0

async : Promise<void>

Load the selection from the specified Channel or Layer. A Layer's pixels' transparency will be used as the selection values. Full opaque pixels yield fully selected pixels.

Copied to your clipboard
await doc.selection.load(doc.channels[3]); // first alpha channel in RGB document

UI Locations:

  • Select > Load Selection...
  • control/command + click on layer thumbnail
  • control/command + click on channel thumbnail

For selecting a path please use PathItem.makeSelection

Parameters

NameTypeDefault valueDescription
from
ComponentChannel | AlphaChannel | Layer
-
The Channel or Layer to load the selection from. Can be located in different document.
mode
-
The selection behavior when a selection already exists. Default SelectionType.REPLACE
invert
boolean
false
True to invert the selection

makeWorkPath

25.0

async : Promise<PathItem>

Create a work path from the active selection.

Copied to your clipboard
await doc.selection.makeWorkPath();

UI Location: Paths panel > Make work path icon

Parameters

NameTypeDefault valueDescription
tolerance
number
2
The tolerance (lower values, higher precision), decimal in the range 0.5..10

resizeBoundary

25.0

async : Promise<void>

Scale the selection itself in percent. Does not affect the active layer.

Copied to your clipboard
await doc.selection.resizeBoundary(50, 50);

UI Location: Select > Transform Selection

Parameters

NameTypeDefault valueDescription
horizontal
number
100
The amount to scale selection horizontally (decimal)
vertical
number
100
The amount to scale selection vertically (decimal)
anchor
-
The anchor position to scale around. Default: AnchorPosition.MIDDLECENTER
interpolation
-
The resampling algorithm to use. Default: InterpolationMethod.BICUBIC

rotateBoundary

25.0

async : Promise<void>

Rotate the selection itself clockwise around the given anchor position. Does not affect the active layer.

Copied to your clipboard
await doc.selection.rotateBoundary(90, constants.AnchorPosition.MIDDLECENTER)

UI Location: Select > Transform Selection

Parameters

NameTypeDescription
angle
number
Angle to rotate the the selection by in degrees (decimal in the range -180..180)
anchor
Anchor position to rotate around. Default: AnchorPosition.MIDDLECENTER
interpolation
The resampling algorithm to use. Default: InterpolationMethod.BICUBIC

save

25.0

async : Promise<void>

Save the selection in a new Alpha Channel.

Copied to your clipboard
await doc.selection.save("My Selection");

UI Location: Select > Save Selection...

Parameters

NameTypeDescription
channelName?
string
The name of the new channel to create (Default: "Alpha 1", "Alpha 2", etc.)

saveTo

25.0

Promise<void>

Save the selection in an existing Alpha Channel (Component Channels are not supported targets).

Copied to your clipboard
// Stores the current selection into an existing alpha channel in RGB document
await doc.selection.saveTo(doc.channels[3]);
// Performing an intersection operation on an alpha channel in RGB document
await doc.selection.saveTo(doc.channels[3], SelectionType.INTERSECT);

Parameters

NameTypeDescription
channel
AlphaChannel
The targeted Alpha channel for the save operation.
mode
The selection behavior when a selection already exists. Default: SelectionType.REPLACE

selectAll

25.0

async : Promise<void>

Select the entire canvas.

If the document has artboards, all the pixels of the artboard that contain the active layer will be selected.

If layers across multiple artboards are active, a single rectangular selection will be made, with bounds wrapping them.

If no artboard is active, all artboards will be selected in the same manner. (The resulting selection might be smaller than the canvas bounds.)

Copied to your clipboard
await doc.selection.selectAll();

UI Location: Select > All


selectBorder

25.0

async : Promise<void>

Create a new selection based on the border of the active selection. The new selection will be an area equivalent to a stroke of that border by the given width in pixels. The result is not limited by canvas bounds.

Copied to your clipboard
await doc.selection.selectBorder(10);

UI Location: Select > Modify > Border...

Parameters

NameTypeDescription
width
number
The width of the border selection (integer in the range 1..200)

selectColumn

25.0

async : Promise<void>

Select a single column of pixels.

Copied to your clipboard
await doc.selection.selectColumn(90);

UI Location: Toolbar > Single Column Marquee Tool

Parameters

NameTypeDescription
x
number
The x coordinate in pixels of the column to select (integer). The range should be within the document width.
mode
The selection behavior when a selection already exists. Default: SelectionType.REPLACE

selectEllipse

25.0

async : Promise<void>

Make an elliptical selection.

Copied to your clipboard
await doc.selection.selectEllipse({top: 0, left: 0, bottom: 100, right: 100});

UI Location: Toolbar > Elliptical Marquee Tool

Parameters

NameTypeDefault valueDescription
bounds
-
The bounds of the selection, as an object with {top, left, bottom, right} properties.
mode
-
The selection behavior when a selection already exists. Default SelectionType.REPLACE
feather
number
0
The amount of feathering in pixels to apply to the selection (decimal in the range 0..1000)
antiAlias
boolean
true
If true, anti-aliasing is applied to the selection

selectPolygon

25.0

async : Promise<void>

Make a polygonal selection.

Copied to your clipboard
await doc.selection.selectPolygon([
{x: 50, y: 10},
{x: 100, y: 90},
{x: 10, y: 40}
]);

UI Location: Toolbar > Polygonal Lasso Tool

Parameters

NameTypeDefault valueDescription
points
{ x: number ; y: number }[]
-
The points to select as an array of objects with {x, y} properties.
mode
-
The selection behavior when a selection already exists. Default: SelectionType.REPLACE
feather
number
0
The amount of feathering in pixels to apply to the selection (decimal in the range 0..1000)
antiAlias
boolean
true
If true, anti-aliasing is applied to the selection

selectRectangle

25.0

async : Promise<void>

Make a rectangluar selection.

Copied to your clipboard
await doc.selection.selectRectangle(
{top: 0, left: 0, bottom: 100, right: 100},
Constants.SelectionType.REPLACE,
10
);

UI Location: Toolbar > Rectangular Marquee Tool

Parameters

NameTypeDefault valueDescription
bounds
-
The bounds of the selection, as an object with {top, left, bottom, right} properties.
mode
-
The selection behavior when a selection already exists. Default: SelectionType.REPLACE
feather
number
0
The amount of feathering in pixels to apply to the selection (decimal in the range 0..1000)
antiAlias
boolean
true
If true, anti-aliasing is applied to the selection

selectRow

25.0

async : Promise<void>

Select a single row of pixels.

Copied to your clipboard
await doc.selection.selectRow(10);

UI Location: Toolbar > Single Row Marquee Tool

Parameters

NameTypeDescription
y
number
The y coordinate in pixels of the row to select (integer). The range should be within the document height.
mode
The selection behavior when a selection already exists. Default: SelectionType.REPLACE

smooth

25.0

async : Promise<void>

Reduce patchiness and smooth sharp corners and jagged lines in the selection. Smooth will also remove isolated groups of pixels that are smaller than the given radius. This effect is useful for cleaning up stray pixels from color-based selections.

Large values might make the selection disappear entirely (.bounds would return null).

Copied to your clipboard
await doc.selection.smooth(32);

UI Location: Select > Modify > Smooth...

Parameters

NameTypeDefault valueDescription
radius
number
-
The sample radius in pixels (integer in the range 1..500)
applyEffectAtCanvasBounds
boolean
false
By default this is false, meaning that any part of the selection that touches the bounds of the canvas will not be affected by the smoothing.

translateBoundary

25.0

async : Promise<void>

Move the selection itself relative to its current position. Does not affect the active layer.

Copied to your clipboard
await doc.selection.translateBoundary(100, 600);

UI Location: Select > Transform Selection

Parameters

NameTypeDescription
deltaX
number
The amount to move the selection horizontally (decimal).
deltaY
number
The amount to move the selection vertically (decimal).
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.