Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to display vertex coordinates of Polygonal Lasso Tool?

Community Beginner ,
Feb 02, 2019 Feb 02, 2019

I use Polygonal Lasso Tool to form a selection like the screenshot below:

Untitled2.png

Now I want to record the accurate vertex coordinates of the Polygonal Lasso Tool. Do you know how to display these coordinates somewhere in Photoshop so that I can record them manually in a notebook or automatically as a file? Thanks a lot.

PS: I'm using Photoshop CC 2019 on Windows 10.

1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 02, 2019 Feb 02, 2019

The price is a bottle of red wine don't go overboard a $15 bottle will do.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

// Set Photoshop to use pixels

app.preferences.rulerUnits = Units.PIXELS;

var thePath = selectedPath();

if (thePath == undefined) {

   alert("No

...
Translate
Adobe
Community Expert ,
Feb 02, 2019 Feb 02, 2019

You may be able to write a Photoshop Script to do that. The script would have Photoshop convert the selection to a Path them process path to get the control points coordinates. There may be  extra points the script could also  write the path to a log file. Set guide line marking the points so you can read them on the rulers and switch between ruler unites  just record the point you want in the unites you want. A path can have many points a list may not fit on your display.

Capture.jpg

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2019 Feb 02, 2019

@JJMack: Thank you. I have no knowledge of writing script in Photoshop and my time budget does not allow me to study it. Could you please share your script with me? I can pay you for the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2019 Feb 02, 2019

hengz80545720  wrote

Do you have a lot or a few of these to do?

Would it work for you to:

  • Convert your selection to a path in the Paths panel
  • Open the Info panel
  • Select an anchor point with the Direct Selection tool (white arrow)
  • Copy the info from the X and Y

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2019 Feb 02, 2019

The price is a bottle of red wine don't go overboard a $15 bottle will do.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

// Set Photoshop to use pixels

app.preferences.rulerUnits = Units.PIXELS;

var thePath = selectedPath();

if (thePath == undefined) {

   alert("No Path Selected");

}

else {

   var myPathInfo = extractSubPathInfo(thePath); 

  var pathPoints = "Path Points\n"

   for(var k=0;k<myPathInfo.length;k++){ 

       pathPoints = pathPoints + "Path" + (k+1) + "\n";

       for(var j=0;j<myPathInfo.entireSubPath.length;j++){

           pathPoints = pathPoints  + "X " + myPathInfo.entireSubPath.anchor[0] + " Y " + myPathInfo.entireSubPath.anchor[1] +"\n";

           MarkX(myPathInfo.entireSubPath.anchor[0]);

          MarkY(myPathInfo.entireSubPath.anchor[1]);

      }

   }

   alert(pathPoints);

}

////// determine selected path //////

function selectedPath () {

   try {

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      var theName = desc.getString(charIDToTypeID("PthN"));

      return app.activeDocument.pathItems.getByName(theName)

   }

   catch (e) {

      return undefined

   }

};

// Return the app preferences

app.preferences.rulerUnits = startRulerUnits;

////// michael l hale’s code //////

function extractSubPathInfo(pathObj){ 

    var pathArray = new Array();// each element can be used as the second arugment in pathItems.add ie doc.pathItems.add("myPath1", [pathArray[0]]); 

    var pl = pathObj.subPathItems.length; 

    for(var s=0;s<pl;s++){ 

        var pArray = new Array(); 

          for(var i=0;i<pathObj.subPathItems.pathPoints.length;i++){ 

             pArray = new PathPointInfo; 

             pArray.kind = pathObj.subPathItems.pathPoints.kind; 

             pArray.anchor = pathObj.subPathItems.pathPoints.anchor; 

//alert("Anchor " + pathObj.subPathItems.pathPoints.anchor );

             pArray.leftDirection = pathObj.subPathItems.pathPoints.leftDirection; 

             pArray.rightDirection = pathObj.subPathItems.pathPoints.rightDirection; 

          }; 

        pathArray[pathArray.length] = new Array(); 

        pathArray[pathArray.length - 1] = new SubPathInfo(); 

        pathArray[pathArray.length - 1].operation = pathObj.subPathItems.operation; 

        pathArray[pathArray.length - 1].closed = pathObj.subPathItems.closed; 

        pathArray[pathArray.length - 1].entireSubPath = pArray; 

    }; 

    return pathArray; 

};

function MarkX(x) {

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc61 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

        var desc62 = new ActionDescriptor();

        var idPstn = charIDToTypeID( "Pstn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc62.putUnitDouble( idPstn, idPxl, x);

        var idOrnt = charIDToTypeID( "Ornt" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idVrtc = charIDToTypeID( "Vrtc" );

        desc62.putEnumerated( idOrnt, idOrnt, idVrtc );

    var idGd = charIDToTypeID( "Gd  " );

    desc61.putObject( idNw, idGd, desc62 );

executeAction( idMk, desc61, DialogModes.NO );

}

function MarkY(y) {

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc63 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

        var desc64 = new ActionDescriptor();

        var idPstn = charIDToTypeID( "Pstn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc64.putUnitDouble( idPstn, idPxl, y );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idHrzn = charIDToTypeID( "Hrzn" );

        desc64.putEnumerated( idOrnt, idOrnt, idHrzn );

    var idGd = charIDToTypeID( "Gd  " );

    desc63.putObject( idNw, idGd, desc64 );

executeAction( idMk, desc63, DialogModes.NO );

}

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2019 Feb 02, 2019

@JJMack: Thank you so much for the script. May I ask one more question: I saved the script into C:\Program Files\Adobe\Adobe Photoshop CC 2019\Presets\Scripts\ShowCoord.jsx. This script now shows up in menu File -> Scripts. Then I initiated the Polygon Lasso Tool and made a selection. But when I clicked the menu to run the script, I was given a message "No Path Selected". I tried to call the script via File -> Scripts -> Browse ... but got the same alert. I checked the script and found it is because line 12 returns undefined. I guess the script thought the selection is not selected (or activated), but it is indeed selected:

Untitled3.png

Could you please tell me how to use the script correctly? Thank you again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2019 Feb 02, 2019

Open the path panel and click on the icon in the bottom to convert the selection to a path the message states you have no path.

Capture.jpg

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2019 Feb 02, 2019

It is working now! I'm so grateful for your help. Thank you!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2019 Feb 02, 2019

Send the red my way.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2023 Apr 24, 2023

Is there updated code for this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2025 Mar 17, 2025
LATEST
#target photoshop

if (app.documents.length > 0) {
    var doc = app.activeDocument;
    var validPath = null;
    
    // Loop through all paths to find one that has points
    for (var i = 0; i < doc.pathItems.length; i++) {
        var tempPath = doc.pathItems[i];
        // Check for compound paths first
        if (tempPath.hasOwnProperty("subPathItems") && tempPath.subPathItems.length > 0) {
            validPath = tempPath;
            break;
        }
        // Then check for a simple path with pathPoints
        if (tempPath.hasOwnProperty("pathPoints") && tempPath.pathPoints.length > 0) {
            validPath = tempPath;
            break;
        }
    }
    
    if (!validPath) {
        alert("No path with points found in the active document.\n\nMake sure you have a visible path or a saved Work Path.");
    } else {
        var coordinates = [];
        
        // If the path is compound (has subPathItems)
        if (validPath.hasOwnProperty("subPathItems") && validPath.subPathItems.length > 0) {
            for (var i = 0; i < validPath.subPathItems.length; i++) {
                var subPath = validPath.subPathItems[i];
                for (var j = 0; j < subPath.pathPoints.length; j++) {
                    var pt = subPath.pathPoints[j];
                    coordinates.push([pt.anchor[0], pt.anchor[1]]);
                }
            }
        }
        // Otherwise, use the pathPoints property directly
        else if (validPath.hasOwnProperty("pathPoints") && validPath.pathPoints.length > 0) {
            for (var i = 0; i < validPath.pathPoints.length; i++) {
                var pt = validPath.pathPoints[i];
                coordinates.push([pt.anchor[0], pt.anchor[1]]);
            }
        }
        else {
            alert("No path points found in the selected path.");
        }
        
        // Build the output string manually
        var output = "var coordinates = [\n";
        for (var i = 0; i < coordinates.length; i++){
            output += "  [" + coordinates[i][0] + ", " + coordinates[i][1] + "]";
            if (i < coordinates.length - 1) {
                output += ",\n";
            }
        }
        output += "\n];";
        
        alert(output);
    }
} else {
    alert("No document is open.");
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines