• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scripting Magic Wand selection by preset color

New Here ,
Oct 19, 2020 Oct 19, 2020

Copy link to clipboard

Copied

Hello,

 

I'm trying to write a script to use the magic wand to select a specific color and contract the selection by 3 pixels. However, the magic wand script requires identify the location of a pixel which doesn't work for me because the location of the specific color changes from image to image. Is there any way to get around this?

 

function magicWand(x,y,t,a,c,s) {
    if(arguments.length < 2) return;// make sure have x,y
    if(undefined == t) var t = 32;// set defaults of optional arguments
    if(undefined == a) var a = true;
    if(undefined == c) var c = false;
     if(undefined == s) var s = false;
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
    desc.putReference( charIDToTypeID('null'), ref );
        var positionDesc = new ActionDescriptor();
        positionDesc.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Rlt'), x );// in pixels
        positionDesc.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Rlt'), y );
    desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Pnt '), positionDesc );
    desc.putInteger( charIDToTypeID('Tlrn'), t);// tolerance
    desc.putBoolean( charIDToTypeID('Mrgd'), s );// sample all layers
    if(!c) desc.putBoolean( charIDToTypeID( "Cntg" ), false );//  contiguous
    desc.putBoolean( charIDToTypeID('AntA'), a );// anti-alias
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};

 

TOPICS
Actions and scripting , Windows

Views

380

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Oct 19, 2020 Oct 19, 2020
You can add an empty layer,
draw a pixel of the desired color in it at position (0,0),
move the layer to position (-1, -1),
apply magicWand (-1, -1),
delete the temporary layer.
 

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 19, 2020 Oct 19, 2020

Copy link to clipboard

Copied

If you kown the color use color range instead of the magic wand. get its lab valuse.

function colorRange(fuzziness, luminance, a, b, luminance2, a2, b2, colorModel) {
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var descriptor3 = new ActionDescriptor();
	descriptor.putInteger( stringIDToTypeID( "fuzziness" ), fuzziness );
	descriptor2.putDouble( stringIDToTypeID( "luminance" ), luminance );
	descriptor2.putDouble( stringIDToTypeID( "a" ), a );
	descriptor2.putDouble( stringIDToTypeID( "b" ), b );
	descriptor.putObject( stringIDToTypeID( "minimum" ), stringIDToTypeID( "labColor" ), descriptor2 );
	descriptor3.putDouble( stringIDToTypeID( "luminance" ), luminance2 );
	descriptor3.putDouble( stringIDToTypeID( "a" ), a2 );
	descriptor3.putDouble( stringIDToTypeID( "b" ), b2 );
	descriptor.putObject( charIDToTypeID( "Mxm " ), stringIDToTypeID( "labColor" ), descriptor3 );
	descriptor.putInteger( stringIDToTypeID( "colorModel" ), colorModel );
	executeAction( stringIDToTypeID( "colorRange" ), descriptor, DialogModes.NO );
}
JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 19, 2020 Oct 19, 2020

Copy link to clipboard

Copied

You can add an empty layer,
draw a pixel of the desired color in it at position (0,0),
move the layer to position (-1, -1),
apply magicWand (-1, -1),
delete the temporary layer.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

I had trouble with finding the right command to add a layer. So I recorded the original color of a pixel in coordinate (0,0), colored pixel in (0,0), and used magic wand on pixel (0,0). When I was done with the pixel, I colored it back to the original color. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

LATEST
activeDocument.artLayers.add()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines