4 Replies Latest reply on Mar 26, 2015 7:38 PM by barbarae

    simulating named points


      Hi, I have some polygons (which I draw manually) that have some points that serve specific functional purposes in my scripts--eg a rotation point, a location for other points to move to, etc.  I have been finding them by running through all the polygon's pathPoints to find the highest point, the point that is highest among the leftmost set of points, etc.  it would be much preferable if I could name these points when I created the polygons, and then just retrieve them by name in the scripts.  But the pathPoint object doesn't have a name property.


      I've thought of creating a polygon of a single point that lies overtop of the point I want to name, and naming the polygon.  The problem there is making sure the polygon always moves with its point. If I group them together, apparently I can't do pathfinder operations on the group.  Similarly, I can make a javascript associative array that maps between a name and the coordinates, but it won't automatically be updated when the point moves.


      Has anyone found an elegant hack to simulate named points in indesign scripts?


      Thanks in advance!



        • 1. Re: simulating named points
          rob day Adobe Community Professional & MVP

          You should ask over in the scripting forum


          Couldn't you get the entire path of the polygon's path (entirePath object) and then save the desired point in the list to a variable?


          In AppleScript:


          tell application "Adobe InDesign CC 2014"


               set polyPath to entire path of item 1 of every path of selection

              --returns a list {{248.8125, 192.75}, {174.9375, 192.75}, {138.0, 260.25}, {174.9375, 327.75}, {248.8125, 327.75}, {285.75, 260.25}}


              set myTransformPoint to item 3 of polyPath

              --returns the point in the list{138.0, 260.25}


          end tell


          I don't know JS very well but something like this:


          var mypoly=app.activeDocument.selection[0].paths[0];

          var myTransformPoint=mypoly.entirePath[2];

          • 2. Re: simulating named points
            barbarae Level 1

            Sorry, I thought I was in the scripting forum. But thanks for your response!


            Saving the point to a variable is a great idea!  But how do I know by looking at the polygon which point of the polygon is item 1 in the pathpoints array?  Or, from the other direction, how do I know which index in the array is assigned to my rotation point? (BTW, These are arbitrary polygons with curved as well as straight edges)


            What I just asked sounds like a dumb question, ie, something I should know, and if it is, please forgive me.:-)



            • 3. Re: simulating named points
              rob day Adobe Community Professional & MVP

              Maybe this helps?


              entire path (list of any) : A list of the coordinates of all of the path points on the path, including anchor points and left- and right-direction points. When creating a path using this property, supply either a list of anchor point coordinates ([[x1, y1], [x2, y2], ...]) or a list of anchor point, left-direction point, and right-direction point coordinates ([[[x1, y1], [x2, y2], [x3, y3]], [[x4, y4], [x5, y5], [x6, y6]], ...]). Note: Providing only anchor points results in a path on which all of the path points are connected with straight line segments; supplying the positions of left- and right-direction points specifies curved line segments. Can return: list of lists of 2 numbers or strings.


              It looks to me the points are listed in the draw order and will include nested lists of direction points if they are there, so IDing the point you are after could get tough. If you use the polygon it looks like the points are counter clockwise from upper left.


              So a list like this is the first left direction handle {0.5, 0.5}, followed by the path point {0.904131908838, 0.382180143836}, and then the right direction handle {1.547970895553, 0.194476537295}



              {{{0.5, 0.5}, {0.904131908838, 0.382180143836}, {1.547970895553, 0.194476537295}}, {{2.299965242172, 0.55926347717}, {2.362465242172, 0.93426347717}, {2.424965242172, 1.30926347717}}, {{2.112465242172, 1.93426347717}, {1.633298575505, 2.017596810503}, {1.154131908838, 2.100930143836}}}


              Screen Shot 2015-03-26 at 5.08.22 PM.png


              Good Luck!

              • 4. Re: simulating named points
                barbarae Level 1

                The way I identify points now is just by the position of their anchor coordinates, relative to geometricBounds, other points, etc.  But it isn't always possible to do precisely, and it requires a lot of spinning through pathPoints arrays.  But once I've identified them in this kludgy manner, I could put them in variables as you suggest, and then keep track of them as my shapes are morphed by whatever script I'm in.  I'll try it!