Skip to main content
Participating Frequently
April 1, 2026
Question

Extendscript: PathItem.length-1 don't select last Path if there's a Symmetry Path at the end

  • April 1, 2026
  • 4 replies
  • 55 views
// Reference the active document
var doc = app.activeDocument;

// Check if there are any paths in the document
if (doc.pathItems.length > 0) {
// Access the last item using the length property (0-indexed)
var lastPath = doc.pathItems[doc.pathItems.length-1];

// Make the path active/selected
lastPath.select();
} else {
alert("No paths found in the document.");
}

Photoshop version: 27.4

Hi, I am making a script and I realize when trying to get the last Path when there is a Symmetry Path being the end, the Path it takes would always be the 1st path. You can make your own document with 2 normal paths and the final being a symmetry path, and test the script yourselves.

 

If I am doing something wrong let me know and how to rectify it tq!

    4 replies

    Stephen Marsh
    Community Expert
    Community Expert
    April 1, 2026

    @Crystal33276269zcyj - I had to do this, excluding by name, it’s messy, but appears to work:

     

    var doc = app.activeDocument;
    var paths = doc.pathItems;

    if (paths.length === 0) {
    alert("No paths in this document.");
    } else {
    var lastIndex = paths.length - 1;
    var lastPath = paths[lastIndex];

    // Exclusion regex: ignore symmetry paths and the Work Path
    var exclude = /(symmetry|work path)/i;

    // Check last path
    if (exclude.test(lastPath.name)) {
    var found = false;

    // Look backwards for the previous non-excluded path
    for (var i = lastIndex - 1; i >= 0; i--) {
    var p = paths[i];
    if (!exclude.test(p.name)) {
    p.select();
    found = true;
    break;
    }
    }

    if (!found) {
    alert("No previous non-symmetry, non-work paths found.");
    }
    } else {
    // Last path is valid — select it
    lastPath.select();
    }
    }

     

    Stephen Marsh
    Community Expert
    Community Expert
    April 1, 2026

    It’s working correctly, selecting the last pathItem in the array, regardless what kind of path. I wonder if it has something to do with:

     

    .pathItems.kind == "PathKind.NORMALPATH"; // "PathKind.CLIPPINGPATH" etc.

     

    I don’t know if the DOM even supports symmetry paths to isolate them by their specific kind...

    Participating Frequently
    April 1, 2026

    Current workaround within what my script does: have script delete all previous paths

    Participating Frequently
    April 1, 2026

    Testing some more, it seems like if theres a symmetry path before the new one, its symmetry path state is not fully gone, and that affects how the path is selected?
    when I edit the any earlier symmetry path points (like deleting a point), things then works as per normal