Move an anchor point

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

rcvalle

Move an anchor point

Post by rcvalle »

Hi,

Is it possible to move a given anchor point from within a script? Thanks in advance.

Best regards,

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Move an anchor point

Post by Mike Hale »

Do you mean an anchor point in a path?. If so the answer is no, not really.

You can not edited paths using a script. It is possible to get all the pathPoints from a path, remove the path, and create an path from that edited info but I have done so only with simple paths with only corner points. I would think it would be much harder to move a smooth point.
rcvalle

Move an anchor point

Post by rcvalle »

Yes, they are anchor points resulting from a text type layer converted to a shape. Also, the anchor points I want to move are corner points. Do you have a quick example of the method you described?
Mike Hale

Move an anchor point

Post by Mike Hale »

Here is how to edit a point on a path by it's anchor position.

Code: Select allfunction extractSubPathInfo(pathObj,oldPoint,newPoint){
    var pathArray = new Array();
    var pl = pathObj.subPathItems.length;
    for(var s=0;s<pl;s++){
        var pArray = new Array();
          for(var i=0;i<pathObj.subPathItems[s].pathPoints.length;i++){
             pArray = new PathPointInfo;
             pArray.kind = pathObj.subPathItems[s].pathPoints.kind;
         if(pathObj.subPathItems[s].pathPoints.anchor[0]==oldPoint[0] &&
               pathObj.subPathItems[s].pathPoints.anchor[1]==oldPoint[1]){
            pArray.anchor = newPoint;
            pArray.leftDirection = newPoint;
            pArray.rightDirection = newPoint;
         }else{
            pArray.anchor = pathObj.subPathItems[s].pathPoints.anchor;
            pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;
            pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;
         }
          };
        pathArray[pathArray.length] = new Array();
        pathArray[pathArray.length - 1] = new SubPathInfo();
        pathArray[pathArray.length - 1].operation = pathObj.subPathItems[s].operation;
        pathArray[pathArray.length - 1].closed = pathObj.subPathItems[s].closed;
        pathArray[pathArray.length - 1].entireSubPath = pArray;
    };
    return pathArray;
};
var myPathInfo = extractSubPathInfo(app.activeDocument.pathItems.getByName('Path 1'),[334,377],[334,590]);
var myPathItem = app.activeDocument.pathItems.add("myNewPath", myPathInfo);
rcvalle

Move an anchor point

Post by rcvalle »

This is exactly what I was looking for. Thank you!