pathToPoints(obj, [addPoints])

Returns an object containing an array of all points, an array of all beziers (points + their anchor points) and an array of all paths (containing its array of points + beziers) of a given pageItem in InDesign. Together with createOutlines() this can be used on text items. Accepts both single paths or a collection/group of paths. When using this on a multi path object (e.g. text with separate paths), the paths property can be used to loop over every path separately, whereas the properties points and beziers contain arrays for all paths combined. An optional second parameter adds interpolated points between existing points, which is helpful for subdividing existing paths.

Type: function

Parameter(s):

  • obj {Object}:

    The pageItem(s) to process point/bezier coordinates of.

  • addPoints {Number} Optional:

    Optional amount of additional interpolated points.

Returns:

  • {Object}:

    Returns object with the following arrays points, beziers, paths

Example(s):

Draw all points of a vector path

noFill();
var myCircle = ellipse(width / 2, height / 2, width / 2, width / 2);
var pts = pathToPoints(myCircle);

for (var i = 0; i < pts.points.length; i++) {
  var pt = pts.points[i];
  ellipse(pt.x, pt.y, 3, 3);
}

With Interpolation between Points

noFill();
var myCircle = ellipse(width / 2, height / 2, width / 2, width / 2);
var pts = pathToPoints(myCircle, 5); // add 5 points between each point

for (var i = 0; i < pts.points.length; i++) {
  var pt = pts.points[i];
  ellipse(pt.x, pt.y, 3, 3);
}

Draw Beziers and handles from Path

noFill();
textSize(400);
var myText = text('S', 0, 0, width, height);
var myOutlines = createOutlines(myText);
var pts = pathToPoints(myOutlines);

beginShape();
for (var i = 0; i < pts.beziers.length; i++) {
  var bz = pts.beziers[i];
  vertex(bz.anchor.x, bz.anchor.y, bz.left.x, bz.left.y, bz.right.x, bz.right.y);
  line(bz.anchor.x, bz.anchor.y, bz.left.x, bz.left.y); // left handle
  line(bz.anchor.x, bz.anchor.y, bz.right.x, bz.right.y); // right handle
}
endShape(CLOSE);

Separated Paths of Beziers

noFill();
textSize(400);
var myText = text('B', 0, 0, width, height);
var myOutlines = createOutlines(myText);
var pts = pathToPoints(myOutlines); // add 3 for more detail

for (var j = 0; j < pts.paths.length; j++) {
  var path = pts.paths[j];

  beginShape();
    for (var i = 0; i < path.beziers.length; i++) {
      var bz = path.beziers[i];
      vertex(bz.anchor.x, bz.anchor.y, bz.left.x, bz.left.y, bz.right.x, bz.right.y);
      line(bz.anchor.x, bz.anchor.y, bz.left.x, bz.left.y); // left handle
      line(bz.anchor.x, bz.anchor.y, bz.right.x, bz.right.y); // right handle
    }
  endShape(CLOSE);
}