8 Replies Latest reply: Sep 16, 2013 3:03 AM by saigon80 RSS

    script with Magic Wand tool ?

    saigon80 Community Member

      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.

        • 1. Re: script with Magic Wand tool ?
          JJMack Community Member

          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

          • 2. Re: script with Magic Wand tool ?
            pixxxel schubser Community Member

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

             

             

             

            • 3. Re: script with Magic Wand tool ?
              saigon80 Community Member

              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

              • 4. Re: script with Magic Wand tool ?
                JJMack Community Member

                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!

                • 5. Re: script with Magic Wand tool ?
                  JJMack Community Member

                  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

                  • 6. Re: script with Magic Wand tool ?
                    Michael L Hale Community Member

                    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);
                    
                    • 7. Re: script with Magic Wand tool ?
                      JJMack Community Member

                      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.

                      • 8. Re: script with Magic Wand tool ?
                        saigon80 Community Member

                        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