9 Replies Latest reply on Mar 19, 2018 1:23 AM by bluecd

    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 Level 1

              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

                    • 7. Re: Get coordinates of path of a text selection
                      bluecd Level 1

                      A questions and amendment:

                       

                      Would anybody advice how to get points' coordinates (3+ distinctive points)  from a pseudo circular selection

                      to fit/circumsize a new circle/ellipse selection upon them? I mean using Adobe Scripting...??

                       

                      The idea is to make first an automatic, rough selection /eg using magic wand/ on a circular object/to extract it from the background/ - this part I have already.

                      Then-having above, I need to precise the selection choosing a few points from that selection, with their coordinates(min.3 of course), distant enough from each other and to circumsize circle or elliptical selection on them. All in scripting of course, for automation.

                      Most probably more than minimum-3 points- and a few iterations would be necessary to circumsize a circle or ellipse fitting 1st, rough selection.

                       

                      cheers, thanks in advance for any hints,

                       

                      bbcd

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

                        Hi bbcd,

                        the easiest way to convert a rough shape to an oval would be:

                         

                        // Here I'm doing a duplicate to retain the rough shape:
                        // ( rough shape selected. )
                        
                        var dupShape = app.selection[0].duplicate();
                        dupShape.convertShape( ConvertShapeOptions.CONVERT_TO_OVAL );
                        

                         

                        Don't know if that will fit in your case.

                        Could you do some screenshots to illustrate your problem?

                         

                        Regards,
                        Uwe

                        • 9. Re: Get coordinates of path of a text selection
                          bluecd Level 1

                          Hello,

                           

                          The idea has been well presented here: Action that remove background and image batch process

                           

                          And I just would like to extend its functionality with sth like this: Circle Fit (Pratt method) - File Exchange - MATLAB Central

                           

                          Be it a circle/as its a special case of an ellipse/ or ellipse, plus enabling additional functionality/settings with smoothing, extending, refining selection path.

                          Hope its possible with Adobe Java scripting, now Iam starting to learn the coding ))

                           

                          Kind regards,

                           

                          bbcd