3 Replies Latest reply on Mar 22, 2015 9:57 AM by barbarae

    remove specific pathPoints from a polygon


      Hi, I'm new here, sorry if this is a dumb question.  I couldn't find it in any of the (rather scanty) documentation on InDesign scripting.


      I have a closed polygon (single path) named myFS and want to remove 2 specific points (  (myleft,mybottom) and (myright, mybottom) ) from it. I know they're in there because of how I constructed the polygon.  Apparently there's no remove method for pathPoints in InDesign (unlike Illustrator). So instead I'm trying to retain all the ones I want, and skip those I don't. Here's what I've tried.  But I don't understand how Points are represented, I guess, because this doesn't work--it never finds the points I want, and so myNewFS is the same polygon as myFS.:


      var myPathPoints = Array();

      var myEntirePath = myFS.paths.item(0).entirePath;

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

              var myPoint = myEntirePath[i];

             if (myPoint[0] == Array(myleft, mybottom)  || myPoint == Array(myright, mybottom)){

                   continue;    // skip the ones I want to remove   

                   } else {                 




      var myNewFS=myDocument.polygons.add();

      myNewFS.paths.item(0).entirePath = myPathPoints;

      myNewFS.fillColor = myDocument.colors.item("RGB Yellow");


      Thanks a lot in advance for your help!



        • 1. Re: remove specific pathPoints from a polygon
          [Jongware] Most Valuable Participant

          It's this construction that does not work:


          if (myPoint[0] == Array(myleft, mybottom) ...


          -- a Javascript limitation, not specific to InDesign's implementation. Compare arrays by comparing their individual elements instead.

          • 2. Re: remove specific pathPoints from a polygon
            Marc Autret Level 5

            Hi Barbara,


            Anyway, the remove() method does exist for PathPoint so you don't need to build a copy of that polygon, just loop through the pathpoints—from the end—and remove the unwanted points according to your criteria.


            Note: on comparing [x,y] coordinates coming from InDesign rulers I strongly recommend you convert numbers into strings and base your code on string comparisons, because obscure rounding issues may occur due to measurement unit conversions and they are undetectable using == or === on numbers. Someday I've encountered a weird case: myPathPoint.anchor[0] was returning some number (say 100) but it wasn't possible to validate the condition myPathPoint.anchor[0]==100, despite the fact that myPathPoint.anchor[0].toSource() was exactly returning Number(100). Coercing the value into a string solved the issue.


            So here is the code I would suggest:


            // ---
            // Given myFS (Polygon, no curve) and
            // myleft, myright, mybottom (Numbers)
            // ---
            var LB = [myleft, mybottom].join('|'),
                RB = [myright, mybottom].join('|'),
                myPathPoints = myFS.paths[0].pathPoints.everyItem().getElements(),
                i = myPathPoints.length, pp, xy;
            while( i-- )
                xy = (pp=myPathPoints[i]).anchor.join('|');
                if( xy==LB || xy==RB ) pp.remove();




            • 3. Re: remove specific pathPoints from a polygon
              barbarae Level 1

              Hi Marc, This did the trick!  Thanks a lot, especially about the InDesign measurement unit conversions!   Barbara