Skip to main content
vasanthakumar L
Known Participant
April 6, 2017
Answered

Find image Vertices

  • April 6, 2017
  • 2 replies
  • 1393 views

Hi Guys,

How to export image vertices data (each x=?, y=?)? Here I attached the image this explain exactly what i want.

Thanks,

Vasanth

    This topic has been closed for replies.
    Correct answer c.pfaffenbichler

    Thanks for your reply.

    Exactly! I want photoshop scripting for generate values of path position.

    Thanks

    Vasanth


    // 2016, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) {

    var myDocument = app.activeDocument;

    if (myDocument.pathItems.length > 0) {

    var theArray = collectPathPointsInfoFromDesc (myDocument, myDocument.pathItems[myDocument.pathItems.length - 1]);

    for (var m = 0; m < theArray.length; m++) {

    alert (("subpathitem "+m+" has the following pathpoints\n"+theArray.join("\n")));

    }

    }

    };

    ////// collect path points coordinates //////

    function collectPathPointsInfoFromDesc (myDocument, thePath) {

    var originalRulerUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.POINTS;

    // based of functions from xbytor’s stdlib;

    var ref = new ActionReference();

    for (var l = 0; l < myDocument.pathItems.length; l++) {

      var thisPath = myDocument.pathItems;

      if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {

      ref.putProperty(cTID("Path"), cTID("WrPt"));

      };

      if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {

      ref.putIndex(cTID("Path"), l + 1);

      };

      if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {

            var idPath = charIDToTypeID( "Path" );

            var idPath = charIDToTypeID( "Path" );

            var idvectorMask = stringIDToTypeID( "vectorMask" );

            ref.putEnumerated( idPath, idPath, idvectorMask );

      };

      };

    var desc = app.executeActionGet(ref);

    var pname = desc.getString(cTID('PthN'));

    // create new array;

    var theArray = new Array;

    var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));

    // for subpathitems;

    for (var m = 0; m < pathComponents.count; m++) {

      var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));

    // for subpathitem’s count;

      for (var n = 0; n < listKey.count; n++) {

      theArray.push(new Array);

      var points = listKey.getObjectValue(n).getList(sTID('points'));

    // for subpathitem’s segment’s number of points;

      for (var o = 0; o < points.count; o++) {

      var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));

      var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];

      var thisPoint = [anchor];

      theArray[theArray.length - 1].push(anchor);

      };

      };

      };

    // by xbytor, thanks to him;

    function cTID (s) { return cTID || cTID = app.charIDToTypeID(s); };

    function sTID (s) { return sTID || sTID = app.stringIDToTypeID(s); };

    // reset;

    app.preferences.rulerUnits = originalRulerUnits;

    return theArray;

    };

    2 replies

    c.pfaffenbichler
    Community Expert
    Community Expert
    April 6, 2017

    You may have to explain what you really mean.

    Do you rotate/otherwise transform Layers/Smart Objects/Shapes/… and in which form do you need the coordinates afterwards?

    By default Photoshop files’ zero-point is the upper left corner by the way.

    vasanthakumar L
    Known Participant
    April 6, 2017

    Hi pfaffenbichler,

    Thanks.

    I want to know about the exact x, y positions of every break points. These values should be given to the scripting side. When i export the trimmed image (png image) its appear square or rectangle shape, because i can't export exact shape of that specified object. So i need to tell every vetice points x,y positions. Here i attached the sample image.

    c.pfaffenbichler
    Community Expert
    Community Expert
    April 6, 2017

    So you are talking about Paths with corner points without Bezier handles?

    Are there multiple Paths or inly ever one per image?

    Getting PathPoint information can be done with a Script as well as creating a txt- or some other file, you may want to ask for help over at

    Photoshop Scripting

    Inspiring
    April 6, 2017

    Hit Cmd + T to get the transform controls. The control bar up at the top will have the x and y values.