12 Replies Latest reply on Mar 21, 2012 4:56 PM by CarlosCanto

    TextFrame Collection Loop visible bound height --JS OR VB

    duhwellhuh Level 1

      Hi Everybody-

      Is there any way to take a collection of textframes in a document, create outlines for each, get the visible bound height of each, and then add text offset from the textframe specifying the visible bound height found from earlier in mm?

       

      If so, can the same technique be used to get the font-family-style and font-size(pt) of each text frame and add them as well before the outline is created?

       

      I'm familiar with creating the outlines because Mark already showed me the light on that. The last 2 operations are what's getting me and doing them for each textframe in the doc.Thanks in advance.

        • 1. Re: TextFrame Collection Loop visible bound height --JS OR VB
          duhwellhuh Level 1

          I see now that it is actually the geometric bounds I'm trying to get. I found a script Carlos made from another post to achieve that with a selection. I just modified the inches to make them mm.

           

          So is there a way to get the font name and size in points? Any help would be appreciated.

          • 2. Re: TextFrame Collection Loop visible bound height --JS OR VB
            CarlosCanto Adobe Community Professional & MVP

            So is there a way to get the font name and size in points? Any help would be appreciated.

             

            var idoc = app.activeDocument;
            var itext = idoc.textFrames[0];
            var itextInfo = itext.textRange.characterAttributes;
            alert("TextFrame Font Name : " + itextInfo.textFont.name);
            alert("TextFrame Font Size : " + itextInfo.size);
            
            1 person found this helpful
            • 3. Re: TextFrame Collection Loop visible bound height --JS OR VB
              duhwellhuh Level 1

              Thanks Carlos! That is a better layout than what I'm working with right now. I actually found one of your older posts to get me going. You have any idea of what I was asking in the original post? I'm to the point now where it will loop through the text items that are selected,  and give me the font name, the point size and place it on top of the textframe. That is all and good, but what I really want to do is get that information and add it to the artboard, then create outlines of the text frame and get the geometric bounds of the outlined textframe and add it to the artboard as well. All in all, I'm trying to achieve a script that will give me a font height of each textFrame. Below is what I got right now. Please let me know if you have any pointers or ideas how to achieve what I'm working towards:

               

               

              //Alteration of Carlos Santos script

              myDoc = app.activeDocument;
              findDims(myDoc.selection);

                  
              function findDims(objs) {
                  for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects
              var myTextRange = objs[i];

                      var vb = objs[i].geometricBounds; // left, top, right, bottom // * changed to geometricBounds

                      var w = (vb[2] - vb[0]);
                      var h = (vb[1] - vb[3]);

                      if (objs[i].parent.typename != "GroupItem") { // Check if parent is a groupItem

                          descFrame = myDoc.textFrames.add(); // Create the text frame
                          var TextInfo = myTextRange.textRange.characterAttributes;
                          var F = TextInfo.textFont.name;
                          var S = TextInfo.size;
                       
                          var H = h/2.834645 ;
                          H = H.toFixed(4); // *

                          descFrame.contents = F +"\n \n" + S  + "\r" + H  + "mm";  // Adds contents to frame
                      
                         
                          var distanceFromTop = 1.125*2.834645 ; // *
                          var x = objs[i].left+w/2-descFrame.width/2; // *
                          var y = objs[i].top + descFrame.height + distanceFromTop;
                      
                         
                          descFrame.position = [x,y]; // *
                         
                  
                      }

              }
              }

              • 4. Re: TextFrame Collection Loop visible bound height --JS OR VB
                CarlosCanto Adobe Community Professional & MVP
                //Alteration of Carlos Santos script

                my last name is Canto

                 

                 

                add this two lines at the end your script, to outline text and get the bounds of it. I printed the geometric bounds to the console.

                        
                descFrame.position = [x,y]; // *
                        
                var myOutlinedText = myTextRange.createOutline();
                        
                $.writeln(myOutlinedText.geometricBounds);
                
                
                • 5. Re: TextFrame Collection Loop visible bound height --JS OR VB
                  duhwellhuh Level 1

                  Thanks Carlo, I'll give it a go. I didn't mean to disrespect you Carlos. I must have just seen the "S" and overlooked the C. Thanks.

                  • 6. Re: TextFrame Collection Loop visible bound height --JS OR VB
                    Muppet Mark Level 5

                    It takes more than a typo to shake off Carlos… I've been trying for ages and he keeps coming back… So much so he's top of the pile… I managed to grid everyone down but not him blast and double blast…

                    • 7. Re: TextFrame Collection Loop visible bound height --JS OR VB
                      duhwellhuh Level 1

                      Not yet, I need to pick his brain some more. I'm too much of a noob to be on that level.

                      • 8. Re: TextFrame Collection Loop visible bound height --JS OR VB
                        CarlosCanto Adobe Community Professional & MVP

                        don't worry about it, no biggie, I know you know my name by now...I threw that in there for no reason at all.

                        • 9. Re: TextFrame Collection Loop visible bound height --JS OR VB
                          CarlosCanto Adobe Community Professional & MVP

                          hahaha, hi Mark, sorry about that, I'm only there because you don't use that account anymore....I'm just keeping it warm for you, so it is comfy when your back at it.

                          • 10. Re: TextFrame Collection Loop visible bound height --JS OR VB
                            duhwellhuh Level 1

                            Thank you Mr. Canto. You showed me the way on this one. I was really beating my head against the wall. Thanks a bunch.

                             

                            Here is the final if anyone is interested:

                             

                            //Alteration of Carlos Canto's cript

                            myDoc = app.activeDocument;
                            findDims(myDoc.selection);

                                
                            function findDims(objs) {
                                for (i=objs.length-1; i>=0; i--) { //loop through your collection of objects
                                    if(objs[i] != "[TextFrame ]" ) {alert("You must select text!");return;} else{
                            var myTextRange = objs[i];
                            myTextRange.duplicate();

                                    var vb = objs[i].geometricBounds; // left, top, right, bottom // * changed to geometricBounds

                                    var w = (vb[2] - vb[0]);
                                    var h = (vb[1] - vb[3]);

                                    if (objs[i].parent.typename != "GroupItem") { // Check if parent is a groupItem

                                        descFrame = myDoc.textFrames.add(); // Create the text frame
                                        var TextInfo = myTextRange.textRange.characterAttributes;
                                        var F = TextInfo.textFont.name;
                                        var S = TextInfo.size;
                                     
                                        var H = h/2.834645 ;
                                        H = H.toFixed(4); // *
                                        S= S.toFixed(0);
                                       
                                    
                                       
                                        var distanceFromTop = 1.125*2.834645 ; // *
                                        var x = objs[i].left - descFrame.width; // *
                                        var y = objs[i].top + descFrame.height + distanceFromTop;
                                    
                                       
                                        descFrame.position = [x,y]; // *
                                       
                                  

                            var myOT= myTextRange.createOutline();
                            var myOTGB = myOT.geometricBounds     //My Outline Geometric Bounds
                                     var h = (myOTGB[1] - myOTGB[3]);
                                     var w = (myOTGB[2] - myOTGB[0]);
                                     var myOTH = h/2.834645 ;
                                       myOTH = myOTH.toFixed(2); //  My Outline Height ROUNDED

                            var myStyle = descFrame.textRange.characterAttributes;
                            myStyle.textFont = app.textFonts.getByName('ArialMT'); //change  font of callout
                            descFrame.contents = F +"\n \n" + S  + "\n\n pt \n\n" + "/\n\n" +  myOTH + "\n\n" + "mm";  //add callout for font, pt, and outlined text height in mm
                            myDoc.groupItems[0].hidden = true //Hide all outlined text
                            }

                             

                             

                                    }

                            }
                            }

                            • 11. Re: TextFrame Collection Loop visible bound height --JS OR VB
                              Muppet Mark Level 5

                              It was my offshore account but now we've been reduced to ONLY 45p in the £ TAX… I don't need it any more… Hum. Does this mean I've got to make the cups of tea now?

                              • 12. Re: TextFrame Collection Loop visible bound height --JS OR VB
                                CarlosCanto Adobe Community Professional & MVP

                                yes please, it is your turn now.....mmmmmm...it is good to be king.