6 Replies Latest reply on May 29, 2014 5:36 AM by Laubender

    Get coordinates of path of a text selection

    poortip87 Level 1

      Hi,

       

      I want to get the coordinates of the path of the selection made on some text content. Is that possible?

       

      Thanks!

        • 1. Re: Get coordinates of path of a text selection
          DaveSofTypefi Level 2

          What do you mean by path? Are you literally talking about text along a path? If so, you should be able to use:

           

          app.selection[0].parentTextFrames[0]

           

          to get a reference to the path or you could use:

           

          app.selection[0].parentStory.textContainers[0]

           

          which at least has you call the thing by a more appropriate name.

           

          I'm assuming you don't have this threaded in a story.

           

          Dave

          • 2. Re: Get coordinates of path of a text selection
            poortip87 Level 1

            Hi Dave,

             

            Thank you for replying, though I am sorry for responding so late. What I want could be better explained by the screenshot below:

            screenshot.jpg

             

            Here you can see that there is a text frame in this document. The text 'Hello' is selected in the text frame. I want to get the coordinates/bounds of the four corners that cover the word. In other words, the coordinates/bounds of the selection.

             

            How can I get this?

            What you suggested returned me the whole text frame. But I want the coordinates or bounds of the sub-text.

            • 3. Re: Get coordinates of path of a text selection
              ping rajesh

              Hi,

               

              You can try as below:

               

              mySelection = app.selection[0].createOutlines(false);
              myBounds = mySelection[0].geometricBounds;
              mySelection[0].remove();
              alert("myBounds: "+myBounds);
              

               

              Thanks,

              ping rajesh

              • 4. Re: Get coordinates of path of a text selection
                poortip87 Level 1

                Hi Rajesh,

                 

                Thanks a tonne for the help... It solved my problem..

                • 5. Re: Get coordinates of path of a text selection
                  poortip87 Level 1

                  Hi Rajesh,

                   

                  A question related to the answer you posted.. The sample preview I loaded had some simple text in a simple text frame.

                  What if the text was written using the path tool? What will be the coordinates returned in that case? When I tried the above sample code with a transformed text frame or path text, I found that the coordinates returned were of an (invisible) rectangle enclosing the selected text.

                   

                  Please see below image for more details,

                  issue.jpg

                   

                  As seen in the above example, a path text that is selected, the coordinates I get are of the yellow rectangle which encloses the text. Is this as far as I am going to get or is there another way?

                  • 6. Re: Get coordinates of path of a text selection
                    Laubender Adobe Community Professional & MVP

                    No. You could get farther :-)

                     

                    The moment the path of the selected text is created through the createOutlines(false) method, you'll have an object that itself is constructed out of paths. And these paths have pathPoints. You could travel through all the pathPoints of all paths created to find out some useful coordinates by looking at the property anchor of a individual pathPoint. That will give you the position as array like that: [x,y].

                     

                    Now you can calculate something like the top most pathPoint etc.pp.

                     

                    Uwe