javascriptphotoshopphotoshop-script

How to load a selection?


I am trying to load my selection like the picture below, where the marching ants go around the edges of my object:

enter image description here

However, i only know how to select the whole layer using this code:

doc.selection.selectAll();

Also, i want to contract the selection by a few pixels and paste it into a channel layer. Any help with that would be great but the most important thing is how to load the selection in the first place.


Solution

  • If you look up in the Javascript Scripting Reference document in your Photoshop install directory you'll see that there are a number of methods available on the selection object to do what you need.

    var doc  = app.activeDocument;
    var channelRef = doc.channels.getByName("TestSelection");
    doc.selection.load(channelRef, SelectionType.REPLACE);
    doc.selection.contract(new UnitValue(20, 'px'));