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 clipboardconst 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 clipboardconst cs = app.activeDocument.colorSamplers[0];const { color, position } = cs; // destructuring assignmentconsole.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 clipboardapp.activeDocument.colorSamplers.removeAll();app.activeDocument.colorSamplers.length; // returns 0
Properties
Name | Type | Access | Min Version | Description |
---|---|---|---|---|
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.0Adds a ColorSampler to the collection at the given {x, y}
coordinates in pixels.
Copied to your clipboardapp.activeDocument.colorSamplers.add({x: 20, y: 20});app.activeDocument.colorSamplers.length; // returns 1
Parameters
Name | Type |
---|---|
position | object |
position.x | number |
position.y | number |
removeAll
24.0void
Removes all ColorSampler instances from this collection.
Copied to your clipboardapp.activeDocument.colorSamplers.removeAll();app.activeDocument.colorSamplers.length; // returns 0