5 Replies Latest reply on Dec 21, 2013 2:11 AM by c.pfaffenbichler

    Scripting the path in Quick Selection Tool

    max_86

      Hi,

       

      I'm trying to build a JS script which:

       

      1. opens an image

      2. selects the quick selection tool

      3. does the selection following a pre-defined path

      4. puts the unselected area to white

      5. saves the image

       

      The problem is in step 3. All the other steps can be recorded with ScriptListener, but the path is not. So the question is:

       

      How can I tell to my script a path to follow while using Quick Selection?

       

      How can I do it, for example, with a very simple path, say a line from pixel (50,50) to (50,200)?

       

      Many thanks!

        • 1. Re: Scripting the path in Quick Selection Tool
          pixxxel schubser MVP & Adobe Community Professional

          You don't need the quick selection tool.

           

          This is one way to make what you want:

           

          // you need as minimum a three points path in an opened document
          // the path must necessarily be named „Path 1“
          app.activeDocument.pathItems.getByName('Path 1').makeSelection(0, true, SelectionType.REPLACE);
          app.activeDocument.selection.invert();
          

           

           

          Hope, this is helpful for you.

          Have fun

           

          • 2. Re: Scripting the path in Quick Selection Tool
            max_86 Level 1

            Thanks for your answer.

             

            I don't understand this:

             

            - Where, in your sample code, I'm saying to Photoshop to use the same selection algorithm used from the Quick Selection Tool?

             

            And also, I don't know how to specify a path. (I know I can find it in the guide, but I'm not so familiar with Photoshop scripting and the Photoshop DOM, so I'd be glad if you give me an example or point to the right resource/page in the guide).

             

            Many many thanks!

            • 3. Re: Scripting the path in Quick Selection Tool
              c.pfaffenbichler Level 9

              This would select the first path and stroke it with the Quick Selection Tool, for the second part it uses the Action Manager recorded with ScriptingListener.plugin.

              app.activeDocument.pathItems[0].select();

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

              var idStrk = charIDToTypeID( "Strk" );

                  var desc7 = new ActionDescriptor();

                  var idnull = charIDToTypeID( "null" );

                      var ref7 = new ActionReference();

                      var idPath = charIDToTypeID( "Path" );

                      var idOrdn = charIDToTypeID( "Ordn" );

                      var idTrgt = charIDToTypeID( "Trgt" );

                      ref7.putEnumerated( idPath, idOrdn, idTrgt );

                  desc7.putReference( idnull, ref7 );

                  var idUsng = charIDToTypeID( "Usng" );

                  var idquickSelectTool = stringIDToTypeID( "quickSelectTool" );

                  desc7.putClass( idUsng, idquickSelectTool );

                  var idPrs = charIDToTypeID( "Prs " );

                  desc7.putBoolean( idPrs, true );

              executeAction( idStrk, desc7, DialogModes.NO );

              • 4. Re: Scripting the path in Quick Selection Tool
                max_86 Level 1

                Thanks for your answer! It seems to work!

                 

                But I have one question: when I use the scriptListerner, and draw a selection with the QuickSelection tool, the listener records this:

                 

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

                var idslct = charIDToTypeID( "slct" );

                    var desc2 = new ActionDescriptor();

                    var idnull = charIDToTypeID( "null" );

                        var ref1 = new ActionReference();

                        var idquickSelectTool = stringIDToTypeID( "quickSelectTool" );

                        ref1.putClass( idquickSelectTool );

                    desc2.putReference( idnull, ref1 );

                executeAction( idslct, desc2, DialogModes.NO );

                 

                How did you manage to record the other stuff?

                • 5. Re: Scripting the path in Quick Selection Tool
                  c.pfaffenbichler Level 9

                  I did not draw manually but used a Path and »Stroke Path« wit the Quick Selection selected.