Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevechap416/467972cad070fea3869dfd267ece881a to your computer and use it in GitHub Desktop.
Save stevechap416/467972cad070fea3869dfd267ece881a to your computer and use it in GitHub Desktop.
Create Rectangular Selection
//Change app units to pixels so the selection below will perform correctly
app.preferences.rulerUnits = Units.PIXELS;
//Selects a 100px by 100px rectangle.
selectRect(0,0,100,100)
function selectRect(top, left, right, bottom)
{
app.activeDocument.selection.deselect()
// =======================================================
var id1 = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id3 = charIDToTypeID( "Chnl" );
var id4 = charIDToTypeID( "fsel" );
ref1.putProperty( id3, id4 );
desc1.putReference( id2, ref1 );
var id5 = charIDToTypeID( "T " );
var desc2 = new ActionDescriptor();
var id6 = charIDToTypeID( "Top " );
var id7 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id6, id7, top );
var id8 = charIDToTypeID( "Left" );
var id9 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id8, id9, left );
var id10 = charIDToTypeID( "Btom" );
var id11 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id10, id11, bottom );
var id12 = charIDToTypeID( "Rght" );
var id13 = charIDToTypeID( "#Pxl" );
desc2.putUnitDouble( id12, id13, right );
var id16 = charIDToTypeID( "Rctn" );
desc1.putObject( id5, id16, desc2 );
executeAction( id1, desc1, DialogModes.NO );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment