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:
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:
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.
app.activeDocument.colorSamplers.removeAll();
app.activeDocument.colorSamplers.length; // returns 0
Properties
Methods
add
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> ColorSampler
Adds a ColorSampler to the collection at the given {x, y} coordinates in pixels.
app.activeDocument.colorSamplers.add({x: 20, y: 20});
app.activeDocument.colorSamplers.length; // returns 1
Parameters
positionposition.xposition.yremoveAll
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> void
Removes all ColorSampler instances from this collection.
app.activeDocument.colorSamplers.removeAll();
app.activeDocument.colorSamplers.length; // returns 0