Methods

Learn Photo Editing

Learn Photo Editing

Get Instant Access

Method

Parameter Type

Returns

()

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

Contract

(By)

Number (Double)

Contracts the selection by the specified amount.

Copy

( [Merge])

Boolean

Copies the selection to the clipboard. When the optional argument is used and set to true, a merged copy is performed (all visible layers in the selection are copied).

()

Clears the current selection and copies it to the clipboard.

Deselect

()

Deselects the current selection.

Expand

(By)

Number (Double)

Expands the selection by the specified amount.

Feather

(By)

Number (Double)

Feathers the edges of the selection by the specified amount.

Fill

[, PreserveTransparency] )

Object (SolidColor, ArtLayer, HistoryState);

Fills the selection (Opacity: 1 -100 as percent).

or String PsColorBlendMode Number (Long) Boolean

Method

Parameter Type

Returns

What it does (Continued)

Grow

(Tolerance, AntiAlias)

Number (Long) Boolean

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

Invert

()

Inverts the selection (deselects the selection and selects the rest of the layer or document).

Note: To flip the selection shape, see Rotate.

Load

(From

[, Combination] [, Inverting])

Channel

PsSelectionType

Loads the selection from the specified channel.

([Tolerance])

Number (Double)

Makes this selection item the work path for this document.

Resize

([Horizontal] [, Vertical] [, Anchor])

Number (Double) Number (Double) PsAnchorPosition

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

ResizeBoundary

([Horizontal] [, Vertical] [, Anchor])

Number (Double) Number (Double) PsAnchorPosition

Changes the size of the selection to the specified dimensions around the specified anchor.

Rotate

(Angle [, Anchor])

Number (Double) PsAnchorPosition

Rotates the selection by the specified amount around the specified anchor point.

RotateBoundary

(Angle [, Anchor])

Number (Double) PsAnchorPosition

Rotates the boundary of the selection around the specified anchor.

Select

(Region [, Type] [, Feather] [, AntiAlias])

Array (Points:

Array (Array (x,y),...) PsSelectionType

Selects the specified region.

Number (Double) Boolean

SelectAll

()

Selects the entire layer.

SelectBorder

(Width)

Number (Double)

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

Method

Parameter Type

Returns

What it does (Continued)

Similar

(Tolerance, AntiAlias)

Number (Long) Boolean

Grows the selection to include pixels throughout the image falling within the tolerance range.

Smooth

(Radius)

Number (Long)

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

Store

PsSelectionType

Saves the selection as a channel.

(StrokeColor, Width

[, PreserveTransparency] )

Object (color) Number (Long) PsStrokeLocation PsColorBlendMode Number (Long) Boolean

Strokes the selection border (opacity: 1 - 100 as percent).

Translate

( [DeltaX] [, DeltaY])

UnitValue UnitValue

Moves the entire selection relative to its current position.

TranslateBoundary

( [DeltaX] [, DeltaY])

UnitValue UnitValue

Moves the selection relative to its current position.

Sample Script

> The following script creates a checkerboard using the following steps:

1. Create an 800 x 800 pixel document.

2. Divide the entire document into 100 x 100 pixel squares.

3. Select every other square in the first row, then shift the selection criteria to select the alternate squares in the following row. Repeat until every other square in the document is selected.

4. Fill the selected squares with the foreground color from the palette.

5. Invert the selection and fill the newly selected squares with the background color from the palette.

6. Deselect the squares to remove the selection outlines (the "marching ants").

Selection.vbs

Dim appRef, startRulerUnits, startTypeUnits, startDisplayDialogs, docSize Dim cells, cellSize, checkersDoc, shiftIt, h, v, eventWait, enumRedrawComplete Dim typeState, keyState, desc

Set appRef = CreateObject("Photoshop.Application") ' Save the current Preferences startRulerUnits = appRef.Preferences.RulerUnits startTypeUnits = appRef.Preferences.TypeUnits startDisplayDialogs = appRef.DisplayDialogs

' Set Photoshop CS2 to use pixels and display no dialogs appRef.Preferences.RulerUnits = 1 'for PsUnits --> 1 (psPixels) appRef.Preferences.TypeUnits = 1 'for PsTypeUnits --> 1 (psPixels) appRef.DisplayDialogs = 3 'for PsDialogModes --> 3 (psDisplayNoDialogs)

' Close all the open documents Do While appRef.Documents.Count appRef.ActiveDocument.Close Loop

' Create variables for the 800 pixel board divided in even 100 x 100 squares docSize = 800 cells = 8

cellSize = docSize / cells ' create a new document

Set checkersDoc = appRef.Documents.Add(docSize, docSize, 72, "Checkers")

' Create a variable to use for selecting the checker board ' That allows me to shift the selection one square to the right 'on every other row, and then shift back for the rows in between. shiftIt = true

' loop through vertically to create the first row v = 0

For v = 0 To (docSize - 1) Step cellSize ' Switch the shift For a new row shiftIt = Not shiftIt

' loop through horizontally h = 0

For h = 0 To (docSize - 1) Step (cellSize * 2) ' push over the cellSize to start with only If shiftIt And h = 0 Then h = h + cellSize End If

If h = 0 And v = 0 Then checkersDoc.Selection.Select(selRegion) Else checkersDoc.Selection.Select(selRegion, 2) ' for PsSelectionType --> 2 (psExtendSelection) End If

' turn this off for faster execution ' turn this on for debugging WaitForRedraw Next Next

' Fill the current selection with the Foreground color checkersDoc.Selection.Fill(appRef.ForegroundColor)

'Invert the selection checkersDoc.Selection.Invert()

' Fill the new selection with the background color checkersDoc.Selection.Fill(appRef.BackgroundColor)

' Clear the selection to get rid of the non-printing borders checkersDoc.Selection.Deselect()

' Reset the application preferences appRef.Preferences.RulerUnits = startRulerUnits appRef.Preferences.TypeUnits = startTypeUnits appRef.DisplayDialogs = startDisplayDialogs

' A helper function for debugging

' It also helps the user see what is going on

' if you turn it off for this example you

' get a flashing cursor for a Number (Long) time

' Save a bit of time by creating the variables only once

Private Sub WaitForRedraw

If VarType(eventWait) = vbEmpty Then eventWait = appRef.charIDToTypeID("Wait") End If

If VarType(enumRedrawComplete) = vbEmpty Then enumRedrawComplete = appRef.charIDToTypeID("RdCm") End If

If VarType(typeState) = vbEmpty Then typeState = appRef.charIDToTypeID("Stte") End If

If VarType(keyState) = vbEmpty Then keyState = appRef.charIDToTypeID("Stte") End If

If VarType(desc) = vbEmpty Then

Set desc = CreateObject("Photoshop.ActionDescriptor") desc.putEnumerated KeyState, typeState, enumRedrawComplete End If appRef.executeAction(eventWait, desc, 3) 'for PsDialogModes --> 3 (psDisplayNoDialogs) End Sub

Was this article helpful?

+1 0
Photoshop CS Mastery

Photoshop CS Mastery

Artists, photographers, graphic artists and designers. In fact anyone needing a top-notch solution for picture management and editing. Set Your Photographic Creativity Free. Master Adobe Photoshop Once and For All - Create Flawless, Dramatic Images Using The Tools The Professionals Choose. Get My Video Tutorials and Retain More Information About Adobe Photoshop.

Get My Free Videos


Post a comment