Skip to main content
Known Participant
September 27, 2011
Answered

want to select path or mask

  • September 27, 2011
  • 1 reply
  • 1120 views

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

This topic has been closed for replies.
Correct answer Muppet Mark

it show this error


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…

1 reply

Inspiring
September 27, 2011

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…

sasientryAuthor
Known Participant
September 28, 2011

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

Inspiring
September 28, 2011

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

     }

 

};