skip to Main Content

I automate Photoshop using JavaScript, here is my code:

var originalRulerUnits = app.preferences.rulerUnits
originalRulerUnits = Units.PIXELS

displayDialogs = DialogModes.NO

var fileRef = new File( "C:\Users\...\Desktop\...\...\test.png" );
app.open( fileRef );
var docRef = app.activeDocument;

So this code works fine, but next when I’m trying

docRef.selection.selectEllipse(
    {top: 50, left: 70, bottom: 140, right: 100},
    constants.SelectionType.EXTEND
);

or

docRef.selection.selectColumn(90);

with or without await keyword, or

docRef.selectEllipse({top: 0, left: 0, bottom: 100, right: 100});

and etc., nothing happens?

I’ve found these methods in Adobe documentation:
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/selection/#selectall

but they aren’t present in photoshop-javascript-ref-2020.pdf , neither in photoshop-scripting-guide-2020.pdf ( https://github.com/Adobe-CEP/CEP-Resources/tree/master/Documentation/Product%20specific%20Documentation/Photoshop%20Scripting )

I’m using Photoshop 25.0.0, but those Instruments (-Elliptical Marquee Tool; -Single Column Marquee Tool; -Polygonal Lasso Tool; -Rectangular Marquee Tool) were in Photoshop for many years, and for example methods like .select()

var shapeRef = [ [x2, y2], [width, y2], [width, height], [x2, height] ];
docRef.selection.select(shapeRef);

or .selectAll() works fine.

So what am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    So, I posted the same question on the Adobe forum: https://community.adobe.com/t5/photoshop-ecosystem-discussions/javascript-why-methods-selectellipse-selectcolumn-selectpolygon-and-etc-don-t-work/m-p/14718959#M818766

    and received the following answer: these methods work only for new UXP/BatchPlay code (.psjs), while ExtendScript/Action Manager code (.jsx) is legacy, and in it, these methods discussed in my question do not work. "These methods can be found in the UXP reference - and not in the Javascript reference."


  2. When in doubt – use the scriptlistener – which will give you this function to select a ellipse (can be changed to rectangle with a few adjustments)

    select_shape(50, 70, 140, 100)
    
    
    // function SELECT shape(top, left, bottom, right)
    // --------------------------------------------------------
    function select_shape(top, left, bottom, right)
    {
    
      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( "Elps" ); //ellipse
      desc1.putObject( id5, id16, desc2 );
      var id15 = charIDToTypeID( "AntA" );
      desc1.putBoolean( id15, true );
      desc1.putObject( id5, id16, desc2 );
    
      executeAction( id1, desc1, DialogModes.NO );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search