Question

I'd like to move a selection I made through the whole document by its width amount (var x2) relatively to its current position. It seems there was a translate function in earlier versions that did exactly what I want but this function now gives an "probably not supported in this version of Photoshop" error. I'm working in Photoshop Extended CS6. This is the selection I have:

 var x2 = 720;
 var y2 = 350;

  docRef.selection.select(Array (Array(0, 0), Array(x2, 0), Array(x2, y2), Array(0, y2)));

I tried to make an equation for that but all I get is garbage selections that aren't even rectangular anymore.

Was it helpful?

Solution

I think the translate (in earlier versions) doesn't work, or is now outmoded, as it's point based, not pixel based.1 point = 4.86127 pixels

I tend to use this function for getting a rectangular or elliptical selection. I find it easier than having to define four limits (top, left, right, bottom) rather than four sets of x & y coords each time.

    selectThis(10, 10, 90, 90, "rect")

// function selectThis (top, left, right, bottom, ellipse or rect [default], antialias [default] )
// ----------------------------------------------------------------------------
function selectThis(top, left, right, bottom, shape, aa)
{
    srcDoc.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 );


    if (shape == "Elps" || shape == "oval")
    {
        var id14 = charIDToTypeID( "Elps" );
        desc1.putObject( id5, id14, desc2 );
        var id15 = charIDToTypeID( "AntA" );
        if (aa == true || aa == undefined)
        {
            desc1.putBoolean( id15, true );
        }
        else
        {
            desc1.putBoolean( id15, false );
        }
    }
    else
    {
        var id16 = charIDToTypeID( "Rctn" );
        desc1.putObject( id5, id16, desc2 );
    }

    executeAction( id1, desc1, DialogModes.NO );
}

Hope this is helpful.

OTHER TIPS

Nevermind this is very simple I guess I had a knot in my head.

This works perfectly:

 var offset = 720;   
 var x2 = 720+offset;
  var y2 = 350;

  docRef.selection.select(Array (Array(0+offset, 0), Array(x2,0), Array(x2, y2), Array(0+offset, y2)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top