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

Index of pathPoints from pathItems Selection

Explorer ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

Using the Direct Selection Tool I would like to target a single anchor point on multiple pathItems and return their index so I can push their respective X and Y coordinates to an array. I am enclosing a code snippet where the index is static and not stemming from the selection.

 

var idoc = app.activeDocument;

var pathSelection = idoc.selection;

var pathAnchors = [];

  for (var i = 0; i < pathSelection.length; i++) {

    var selectedPath = pathSelection[i];

    // anchor point of the selected path
    var selectedAnchorPoint = selectedPath.pathPoints[0]; // help acquiring pathPoints index from selection

    // x and y coordinates
    var anchorX = selectedAnchorPoint.anchor[0];
    var anchorY = selectedAnchorPoint.anchor[1];

    pathAnchors.push({x: anchorX, y: anchorY});

    alert("<<<  Array Contents  >>>\n\nX: " + pathAnchors[i].x + "\n\nY: " + pathAnchors[i].y);

  }
TOPICS
How-to , Scripting

Views

137

Translate

Translate

Report

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

Enthusiast , Feb 02, 2025 Feb 02, 2025

If we check that a point on the path is selected, we don't need the index separately to get its anchor coordinates immediately.

(function () {
  var selectedPoints = [];

  for (var i = 0; i < app.selection.length; i++) {
    var item = app.selection[i];

    if (item.typename === "PathItem" && item.hasOwnProperty("pathPoints")) {
      for (var j = 0; j < item.pathPoints.length; j++) {
        var currPoint = item.pathPoints[j];
        // Check if the pathPoint is selected
        if (currPoint
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Feb 02, 2025 Feb 02, 2025

Copy link to clipboard

Copied

If we check that a point on the path is selected, we don't need the index separately to get its anchor coordinates immediately.

(function () {
  var selectedPoints = [];

  for (var i = 0; i < app.selection.length; i++) {
    var item = app.selection[i];

    if (item.typename === "PathItem" && item.hasOwnProperty("pathPoints")) {
      for (var j = 0; j < item.pathPoints.length; j++) {
        var currPoint = item.pathPoints[j];
        // Check if the pathPoint is selected
        if (currPoint.selected === PathPointSelection.ANCHORPOINT) {
          selectedPoints.push({
            x: currPoint.anchor[0],
            y: currPoint.anchor[1]
          });
        }
      }
    }
  }
})();

Votes

Translate

Translate

Report

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
Explorer ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

I overlooked implementing the hasOwnProperty method along with PathPointSelection.ANCHORPOINT. Thank you for taking the time and the valuable feedback.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

Can you help me take this one step further? Assuming the pathItems are a new selection, using the "selectedPoints" array to match coordinates and select the achorpoints.

Votes

Translate

Translate

Report

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
Enthusiast ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

What does this mean? A function should loop through all pathItems in the document and their anchor points, check the coordinates of each anchor point against the array, and select the anchor if a match is found?

 

Or should the user select a pathItem and the function check if the anchor points match the coordinates from the array and leave only the matching anchor points selected?

 

Adobe Illustrator can also have fractional coordinates that differ by a small amount. For example, if two points match, but one has a coordinate of X: 123.000 and the other has a coordinate of X: 122.999.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

What I would like to do:

 

  1.  Select pathItem anchor point(s) with Direct Selection Tool and store the coordinates to "selectedPoints" array (pathItems will have unique names).
  2. At some other point, select the same pathItem via script and by matching coordinates in "selectedPoints" array automatically select the matching anchor point(s). I will store the coordinates in their original form and understand that the pathItem can't move in order for the anchor point selection to work.

 

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

Have you considered such a solution? If the paths are the same, their order in layers has not changed: 5 objects were selected, next time the same 5 objects will be selected. Then you can store an array of object data: index or unique name in the document of each path (even easier), indexes of points of each path that need to be selected again. Maybe you don't need to store X, Y coordinates here.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 03, 2025 Feb 03, 2025

Copy link to clipboard

Copied

LATEST

I agree that using the index values instead of the coordinates makes more sense. I guess what I am really after, and once I figure it out I can use it in many other ways, is to use the array to select the anchors. Push the pathItem name and anchor point index of the selected anchors to "selectedPoints" array and then use it to match and reselect the anchors at some other time.

Votes

Translate

Translate

Report

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