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
const app = require("photoshop").app;
app.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
const cs = app.activeDocument.colorSamplers[0];
const { color, position } = cs; // destructuring assignment
console.log(color.rgb); // returns a SolidColor object:
// {red: 0, green: 255, blue: 0, model: ColorModel.RGB}
console.log(position); // returns an object: {x: 20, y: 20}

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

Copied to your clipboard
app.activeDocument.colorSamplers.removeAll();
app.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
app.activeDocument.colorSamplers.add({x: 20, y: 20});
app.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
app.activeDocument.colorSamplers.removeAll();
app.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.