Skip to main content
Participant
July 11, 2024
Answered

From drawing to code...

  • July 11, 2024
  • 1 reply
  • 182 views

I know how to write the code (*.jsx) that will draw a path in Illustrator. By path I mean a number of path points (anchor point, pair of direction points, ...).

 

BUT is there a way to ‘get’ the location of .Anchor, .LeftDirection, .RightDirection. from a selected path? So, from drawing to code...

This topic has been closed for replies.
Correct answer m1b

Hi @Paul_St_George, sure... have a look at this:

(function () {

    var doc = app.activeDocument;
    var pathItem = doc.selection[0];

    if ('PathItem' !== pathItem.constructor.name)
        return alert('Please select a path item and try again.');

    for (var i = 0, p; i < pathItem.pathPoints.length; i++) {

        p = pathItem.pathPoints[i];

        alert(
            'PathPoint ' + i
            + '\nanchor: ' + p.anchor
            + '\nleftDirection: ' + p.leftDirection
            + '\nrightDirection: ' + p.rightDirection
        );

    }

})();

You can directly set those properties too, eg.

p.anchor = [10,20];

See PathPoint docs. 

- Mark

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 11, 2024

Hi @Paul_St_George, sure... have a look at this:

(function () {

    var doc = app.activeDocument;
    var pathItem = doc.selection[0];

    if ('PathItem' !== pathItem.constructor.name)
        return alert('Please select a path item and try again.');

    for (var i = 0, p; i < pathItem.pathPoints.length; i++) {

        p = pathItem.pathPoints[i];

        alert(
            'PathPoint ' + i
            + '\nanchor: ' + p.anchor
            + '\nleftDirection: ' + p.leftDirection
            + '\nrightDirection: ' + p.rightDirection
        );

    }

})();

You can directly set those properties too, eg.

p.anchor = [10,20];

See PathPoint docs. 

- Mark