Edit in GitHubLog an issue

ColorSamplers

A collections class allowing for array access into a document's ColorSamplers

Access this collection through the Document.colorSamplers property. For instance, the following adds a new colorSampler to the collection:

Copied to your clipboard
1const app = require("photoshop").app;
2app.activeDocument.colorSamplers.add({x: 20, y: 20});

A colorSampler can be access through the collection's [index] property, and then queried for its properties. For example, the following gets the first colorSampler in the collection, and then unpacks its color and position properties via a destructuring assignment to get the sampled color as a SolidColor object and its current position as an {x, y} object:

Copied to your clipboard
1const cs = app.activeDocument.colorSamplers[0];
2const { color, position } = cs; // destructuring assignment
3console.log(color.rgb); // returns a SolidColor object:
4 // {red: 0, green: 255, blue: 0, model: ColorModel.RGB}
5console.log(position); // returns an object: {x: 20, y: 20}
6

To empty the colorSamplers collection, use the removeAll() method.

Copied to your clipboard
1app.activeDocument.colorSamplers.removeAll();
2app.activeDocument.colorSamplers.length; // returns 0

Properties

NameTypeAccessMin VersionDescription
length
number
R
24.0
Number of ColorSampler elements in this collection. ```javascript // A new document starts with no colorSamplers app.activeDocument.colorSamplers.length; // returns 0 ```
parent
Document
R
24.0
The owner Document of this ColorSamplers collection.

Methods

add

24.0

ColorSampler

Adds a ColorSampler to the collection at the given {x, y} coordinates in pixels.

Copied to your clipboard
1app.activeDocument.colorSamplers.add({x: 20, y: 20});
2app.activeDocument.colorSamplers.length; // returns 1

Parameters

NameType
position
object
position.x
number
position.y
number

removeAll

24.0

void

Removes all ColorSampler instances from this collection.

Copied to your clipboard
1app.activeDocument.colorSamplers.removeAll();
2app.activeDocument.colorSamplers.length; // returns 0
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.