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

script with Magic Wand tool ?

Guest
Sep 14, 2013 Sep 14, 2013

I'm new and I need help with a script that using Magic Wand Tool (tolerance 255, anti alias , contiguous)  click at middle center every image. Many thanks previous ! My images are transparent with many objects in each and I just want to choose the middle_center object and eliminate the others, so i need this scripts.

TOPICS
Actions and scripting
2.7K
Translate
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
Adobe
Community Expert ,
Sep 15, 2013 Sep 15, 2013

I think you woul need to create a function from Scriptlistener code for the magic wand tool where your working with units pixels and you  pass the x and y pixel values for the document center when you use the function. Something like

function MagicWand(x,y) {

/ =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc425 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref134 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref134.putProperty( idChnl, idfsel );

    desc425.putReference( idnull, ref134 );

    var idT = charIDToTypeID( "T   " );

        var desc426 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc426.putUnitDouble( idHrzn, idPxl, 583.000000 );  <------------- replace the hard coded 583 with var X

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc426.putUnitDouble( idVrtc, idPxl, 332.000000 ); <--------------- replace the hard coded 332 with vat y

    var idPnt = charIDToTypeID( "Pnt " );

    desc425.putObject( idT, idPnt, desc426 );

    var idTlrn = charIDToTypeID( "Tlrn" );

    desc425.putInteger( idTlrn, 255 );

    var idAntA = charIDToTypeID( "AntA" );

    desc425.putBoolean( idAntA, true );

executeAction( idsetd, desc425, DialogModes.NO );

}

Also use your own Scriptlistener code make sure of the all setting used point sample size, only current layer,  antialias, etc.

Message was edited by: JJMack

JJMack
Translate
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 ,
Sep 15, 2013 Sep 15, 2013

@JJMack,

why you do not work with percent?

Give this line 13-17 (in your code) a chance.

        var idPxl = charIDToTypeID( "#Prc" );

        desc426.putUnitDouble( idHrzn, idPxl, 50 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Prc" );

        desc426.putUnitDouble( idVrtc, idPxl, 50 );

Translate
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 ,
Sep 15, 2013 Sep 15, 2013

If you want to work and switch between units that is fine.  I normally work with absolute pixels.  When things are relative particularly percent you may stumble when finding a document orientation and aspect ratio for width is 100% and height is 100%  is a square world NO!

JJMack
Translate
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
Guest
Sep 15, 2013 Sep 15, 2013

Thanks Mr.JJMack for your help ! I dont know much about scripts and fuction also . After some trials with your suggestion, it's worked !

also thanks schubser . Wish all you luck from Vietnam

Translate
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 ,
Sep 15, 2013 Sep 15, 2013

I think you may have some problem look at what was selected in this screen capture note sample size is as large as can be

mwcy.jpg

JJMack
Translate
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
Guru ,
Sep 15, 2013 Sep 15, 2013

To have better control over what is selected you need to add other arguments to the scriptlistener function.

function magicWand(x,y,tolerance,anit_alias,contiguous,sampleAll) {

    if(arguments.length < 2) return;// make sure have x,y - other arguments are optional

    if(undefined == tolerance) var tolerance = 32;// set defaults of optional arguments

    if(undefined == anit_alias) var anit_alias = true;

    if(undefined == contiguous) var contiguous = false;

     if(undefined == sampleAll) var sampleAll = 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'), tolerance);

    desc.putBoolean( charIDToTypeID('Mrgd'), sampleAll );

    if(!contiguous) desc.putBoolean( charIDToTypeID( 'Cntg' ), false );

    desc.putBoolean( charIDToTypeID('AntA'), anit_alias );

    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );

};

magicWand(100,100,10,true,true);

Translate
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 ,
Sep 15, 2013 Sep 15, 2013

The OP wanted   (tolerance 255, anti alias , contiguous)  as a constant  he is trying to select a centered object where there are many objects on a single layer all surrounded by a transparent area. Still nothing was stated about sample size. If the sample size it a single point or small. I feel the magic wand may not select their whole center object.

JJMack
Translate
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
Guest
Sep 16, 2013 Sep 16, 2013
LATEST

You are right Mr. JJMack  Your example may be not very often case that Red Blue and Green hue are completely saturated, and highly opposed.  I guess. We can apply one more step in action to ensure a full selection : Select / Grow    (tolerrance 255 ) without care sample size

Translate
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