6 Replies Latest reply on Oct 1, 2011 10:28 AM by sasientry

    want to select path or mask

    sasientry

      path.pngalpha.png

       

      if file have path named "Path 1"

       

      i want selection from that path

       

      else if there is no path  please check channel named "Alpha 1" is there i want selection from that channel

       

      please help me

        • 1. Re: want to select path or mask
          Muppet Mark Level 5

          Depending on the state of your documents you may be able to use something like this…

           

          var doc = app.activeDocument;
          
          if ( doc.pathItems.length > 0 ) {
            
               doc.pathItems[0].makeSelection( 0, true, SelectionType.REPLACE );
            
               doc.pathItems[0].deselect();
          
          } else {
            
               if ( doc.channels[ doc.channels.length-1 ].kind == ChannelType.SELECTEDAREA ) {
            
                    doc.selection.load( doc.channels[ doc.channels.length-1 ], SelectionType.REPLACE, false );
            
               }
            
          };
          
          

           

          It should use a path first then if no paths the last channel… Otherwise it will do nothing…

          • 2. Re: want to select path or mask
            sasientry Level 1

            hi

             

            i have two selection type

             

            path or mask

             

            if i have path  i want selection from the path

            if i dont have path i want selection from the mask

             

            selection taken from path or mask

            • 3. Re: want to select path or mask
              Muppet Mark Level 5

              Did you try it… This would look for the alpha by name rather than position…

               

              var doc = app.activeDocument;
              
              if ( doc.pathItems.length > 0 ) {
                
                   doc.pathItems[0].makeSelection( 0, true, SelectionType.REPLACE );
                
                   doc.pathItems[0].deselect();
              
              } else {
              
                        try {
                
                             doc.selection.load( doc.channels.getByName('Alpha 1'), SelectionType.REPLACE, false );
                
                        } catch(e) {}
                   }
                
              };
              
              • 4. Re: want to select path or mask
                sasientry Level 1

                dffg.png

                 

                it show this error

                • 5. Re: want to select path or mask
                  Muppet Mark Level 5

                  That will learn me to be lazy and copy/paste/edit in the browser window…

                   

                   

                  var doc = app.activeDocument;
                  
                  if ( doc.pathItems.length > 0 ) {
                    
                            doc.pathItems[0].makeSelection( 0, true, SelectionType.REPLACE );
                    
                            doc.pathItems[0].deselect();
                  
                  } else {
                  
                            try {
                    
                                      doc.selection.load( doc.channels.getByName('Alpha 1'), SelectionType.REPLACE, false );
                    
                            } catch(e) {}
                    
                  };
                  
                  

                   

                  Would have thought you could have sorted that mistake thou…

                  • 6. Re: want to select path or mask
                    sasientry Level 1

                    super i got good answer thank u very much