简体   繁体   中英

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"]
     );
}

更好的是,在开始之前删除所有样本:

app.activeDocument.colorSamplers.removeAll();

No worries - found the solution - just add: theSampler.remove(); before the end of the for loop ;-) Doh!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM