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

Script with magic wand

Engaged ,
Jul 08, 2010 Jul 08, 2010

Copy link to clipboard

Copied

I noticed there's no documentaion on scripting (javascript) with the magic wand selection. I'd assume that it's along the lines of magicwand.(X,Y).tolerance.contigious.true.samplealllayers.true. or something like that. But it's guess work.

var id176 = charIDToTypeID( "setd" );
    var desc34 = new ActionDescriptor();
    var id177 = charIDToTypeID( "null" );
        var ref15 = new ActionReference();
        var id178 = charIDToTypeID( "Chnl" );
        var id179 = charIDToTypeID( "fsel" );
        ref15.putProperty( id178, id179 );
    desc34.putReference( id177, ref15 );
    var id180 = charIDToTypeID( "T   " );
        var desc35 = new ActionDescriptor();
        var id181 = charIDToTypeID( "Hrzn" );
        var id182 = charIDToTypeID( "#Pxl" );
        desc35.putUnitDouble( id181, id182, 0.000000 );
        var id183 = charIDToTypeID( "Vrtc" );
        var id184 = charIDToTypeID( "#Pxl" );
        desc35.putUnitDouble( id183, id184, 0.000000 );
    var id185 = charIDToTypeID( "Pnt " );
    desc34.putObject( id180, id185, desc35 );
    var id186 = charIDToTypeID( "Tlrn" );
    desc34.putInteger( id186, 32 );
    var id187 = charIDToTypeID( "Mrgd" );
    desc34.putBoolean( id187, true );
    var id188 = charIDToTypeID( "AntA" );
    desc34.putBoolean( id188, true );
executeAction( id176, desc34, DialogModes.NO );

I've got the above by the old script listener and I was just trying to tidy it up (and learn a bit in the process)

Cheers

TOPICS
Actions and scripting

Views

4.5K

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

Guru , Jul 08, 2010 Jul 08, 2010

This is one of the things you can only do with scriptlistener. Here is one way to clean up the code.

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'), c

...

Votes

Translate

Translate
Adobe
Guru ,
Jul 08, 2010 Jul 08, 2010

Copy link to clipboard

Copied

This is one of the things you can only do with scriptlistener. Here is one way to clean up the code.

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

You could clean it up more by adding data type checks for the arguments.

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
Community Beginner ,
Oct 12, 2017 Oct 12, 2017

Copy link to clipboard

Copied

This is a really useful script. Thank you a lot!

Do you know how to inverse the selection?

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
Community Expert ,
Oct 13, 2017 Oct 13, 2017

Copy link to clipboard

Copied

LATEST

Unfortunately Mike Hale is no longer with us.

Inverting a Selection should be do-able by DOM-code:

activeDocument.selection.invert();

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