Search code examples
javascriptcolor-pickerphotoshop-script

Clear color samples in photoshop with script


I'm trying to write an app to build up a digital 'map' of an image in Photoshop using JavaScript. Basically this involves using the colorSampler to get the rgb of a certain pixel, storing the values in an object and moving onto the next one. All is working fine except when I get to ten readings (ie the info panel is full) I get:

'The command "Make" is currently not available".

Any idea how I can clear the colour samples via a script so that the process can continue or, failing that, can anyone think of any workarounds or hacks?

Script as it stands is as follows:

var vertical_pass = {};

for(i=0; i<=10; i++){

    // set sampler position
    var theSampler = app.activeDocument.colorSamplers.add([0 + i, 1]);

    // Add readings from sampler to object
    vertical_pass["vp_" + i] = {
        "x": i,
        "y": 1,
        "r": Math.round(theSampler.color.rgb.red),
        "g": Math.round(theSampler.color.rgb.green),
        "b": Math.round(theSampler.color.rgb.blue)
    };

    alert(
        "x coords: " + vertical_pass["vp_" + i]["x"] +
        ". y coords: " + vertical_pass["vp_" + i]["y"] +
        ". red: " + vertical_pass["vp_" + i]["r"] +
        ". green: " + vertical_pass["vp_" + i]["g"] +
        ". blue: " + vertical_pass["vp_" + i]["b"]
     );
}

Solution

  • Even better, remove all samples before starting:

    app.activeDocument.colorSamplers.removeAll();