3 Replies Latest reply on Jun 1, 2017 1:49 AM by Sudha K

    CreateOutlines - Para with anchored Object

    Sudha K Level 1

      Hi,

       

           I am getting text bounds using createoutline method.  Its working fine for the text/paragraph. But when the text contains anchored objects its returning bounds including the anchored object. I need to get the position of the selected text alone.

       

       

      Screen shot 2017-04-21 at 09.26.50.png

       

       

      I need to get the bounds of Sample text alone. Without anchored objects. If anyone knows pls let me know.

       

      Code:

       

      Main(); 
      exit()
      function Main() { 
          var text = app.selection[0]; 
          var arr = text.createOutlines(false); 
          var outlinedText = arr[0]; 
          outlinedText.select()  
          var gb = outlinedText.geometricBounds; 
          alert(gb)
          outlinedText.remove(); 
        • 1. Re: CreateOutlines - Para with anchored Object
          Loic.Aigon Adobe Community Professional

          Is it worth outlining the text ? text object have several properties from which you could presume bounds.

           

          Given a single word not being hyphenated across frames:

          var aWord = app.selection[0];

          var vps = app.activeDocument.viewPreferences.properties;

          app.activeDocument.viewPreferences.properties = {

            horizontalMeasurementUnits : MeasurementUnits.POINTS,

            verticalMeasurementUnits : MeasurementUnits.POINTS,

          }

          var x1 = aWord.horizontalOffset;

          var x2 = aWord.endHorizontalOffset;

          var y2 = aWord.baseline;

          var y1 =  y2-aWord.pointSize;

          app.activeDocument.rectangles.add( {geometricBounds : [y1, x1, y2, x2] } );

           

           

          app.activeDocument.viewPreferences.properties = vps;

           

          Well in a perfect world.However I can admit the final algorithm would be far more complicated considering all the special cases.

          • 2. Re: CreateOutlines - Para with anchored Object
            Laubender Adobe Community Professional & MVP

            Hi Sudha,

            try to outline every single character of your selection one by one.

            You could calculate bounds or whatever later after storing individual geometric bounds for every character you are able to outline.

             

            var text = app.selection[0];
            var e;
            var characters = text.characters.everyItem().getElements();
            var allGeoBounds = [];
            
            for(var n=0;n<characters.length;n++)
            {
            try{
            var outlinedDupCharacter = characters[n].createOutlines(false);
            }catch(e){continue};
            allGeoBounds[allGeoBounds.length++] = outlinedDupCharacter[0].geometricBounds;
            outlinedDupCharacter[0].remove();
            };
            
            $.writeln(allGeoBounds.join("\r"));
            

             

            Regards,
            Uwe

            • 3. Re: CreateOutlines - Para with anchored Object
              Sudha K Level 1

              Hi,

                   Sorry for late reply....

                 

              Thank you... Its returning bounds of each character after creating outlines.  When using characters, will it take time to process??

               

              I have used createOutlines for selection (Word/Paragraphs) but sometimes document getting quit. Dont know why its happening?