11 Replies Latest reply on Jan 11, 2016 10:16 PM by aviR

    Length of text upto the aligned character

    aviR Level 1

      Hello All

      I m stuck at a place. Need help

      I want to get the length of characters in a table cell, upto the aligned character. For Example:- if a cell contains text such as "099.27432943", I want the length of "099" and "27432943" separately. And also the width of the character "." .

      Can anyone give me some ideas on this?

      Thank You

        • 1. Re: Length of text upto the aligned character
          Laubender Adobe Community Professional & MVP

          Hi aviR,

          do you mean the number of characters before and after the dot?
          Or do you mean the length in mm (or points etc.) for the two parts of the number?

           

          What would you like to do with the results?

           

          Uwe

          • 2. Re: Length of text upto the aligned character
            aviR Level 1

            Hii

            I mean number of characters before and after the dot.

            I want to set width according to these values

            • 3. Re: Length of text upto the aligned character
              Laubender Adobe Community Professional & MVP

              What width do you like to set?
              The width of the cell? Do you want to find out the minimum width of the cell that is necessary to keep the number in one single line?

               

              You see, it's still not clear to me what you like to accomplish.

               

              Please show a before/after comparison with screenshots.
              (For posting a screenshot use the formatting capabilities of the forum software – the camera icon. Don't send the screenshot by mail to the forum)

               

              Uwe

              • 4. Re: Length of text upto the aligned character
                aviR Level 1

                All I want is the length of the characters before and after the dot.

                How can i do that??

                • 5. Re: Length of text upto the aligned character
                  Laubender Adobe Community Professional & MVP

                  Just to give you some ideas, because I don't know how versatile you are with InDesign ExtendScript scripting:

                   

                  // Let's assume, that a table is selected in the active document:
                  
                  var table = app.selection[0];
                  var contentsArray = table.contents;
                  
                  for(var n=0;n<contentsArray.length;n++)
                  {
                      // If there is no "." in the contents of a cell, step to the next iteration of the loop:
                      if(!contentsArray[n].match(/\./)){continue};
                     
                      // Build an array of the contents. That's a bit fuzzy, because the contents could contain more than one "." perhaps.
                      // But I hope, you get the idea:
                     
                      var splitContentsStringArray = contentsArray[n].split(".");
                      var lengtArray = new Array();
                  
                      for(var s =0;s<splitContentsStringArray.length;s++)
                      {
                          var contents = splitContentsStringArray[s];
                          var contentsLength = contents.length;
                         
                          lengtArray[lengtArray.length++] = contentsLength;
                         
                          // Show the results in the JavaScript Console of the ESTK:
                          $.writeln(n+"\t"+s+"\t"+contents+"\t"+contentsLength);
                      };
                  
                      // Get the width of the ".". That will mean working with formatted text,
                      // a totally different thing than working with the property "contents":
                     
                      var insertionPointBeforeTheFirstDot = table.cells[n].texts[0].insertionPoints[lengtArray[0]];
                      var insertionPointAfterTheFirstDot = table.cells[n].texts[0].insertionPoints[lengtArray[0]+1];
                     
                      var width = insertionPointAfterTheFirstDot.horizontalOffset - insertionPointBeforeTheFirstDot.horizontalOffset;
                     
                      // Show the result in the JavaScript Console of the ESTK:
                      $.writeln("width of first \".\" in cell "+n+"\t"+width);
                     
                  };
                  

                   

                  Note:

                  The width of the dot will only work for tables with cells, where the text is not rotated. And where the table is not rotated.

                  The width in calculated from the first insertion point before the dot and the first insertion point after the dot.

                  The width is not calculated by the glyph's width, wich will/can be different.

                  (I still don't know what you like to accomplish)

                   

                  You'll find properties, values, methods, references about objects here (CS6 and below):

                  Indesign JavaScript Help

                  InDesign ExtendScript API (8.0)

                   

                  For CC 2014:

                  InDesign ExtendScript API (10.0)

                  For CC 2015:

                  http://www.indesignjs.de/extendscriptAPI/indesign11/

                   

                  Uwe

                  • 6. Re: Length of text upto the aligned character
                    aviR Level 1

                    Hi Laubender

                    Thank U so much for the reply. I was not actually clear with the requirement until now.

                    Which is:

                    I have a table that contains texts like "111.32659874"

                    I have to expand the table cell width to clear overset.

                    And then I have to do character alignment where the texts in all the cells have to aligned to the dot

                    And for which i need the width of the numbers before and after the dot so that I can set the maximum cell width

                    • 7. Re: Length of text upto the aligned character
                      aviR Level 1

                      And also the width if the dot and the right and left inset of the cell

                      • 8. Re: Length of text upto the aligned character
                        Laubender Adobe Community Professional & MVP

                        Hi aviR,

                        it's very hard to help you with this task without knowing much more of the table's contents.

                        Sometimes overset of the cells cannot be cleared because some formatting is forcing a permanent overset.

                         

                        Can you show a screenshot of the overset table cells?

                        (Use the camera icon of the editor in the forum controls. Do not attach the screenshot by mail.)


                        Something like that where the story view of the selected table is showing its contents.

                        Also important showing the invisible characters like # for the end of story.

                        ShowingTheTable-TexteditMode-ShowingStoryWindow.png

                         

                        Uwe

                        • 9. Re: Length of text upto the aligned character
                          aviR Level 1

                          Overset is getting cleared for the time being without any trouble.

                          But I am unable to get the length of "111" and "32659874"

                          • 10. Re: Length of text upto the aligned character
                            Laubender Adobe Community Professional & MVP

                            If your goal is to change the width of a column until a distinct number of lines of text in a cell is reached, you can try the script below.

                            Select one single cell and let it run. You can adapt the values of three variables to your needs. Also study the structure of the while loop.

                             

                            // ExpandTheWidthOfColumn-UntilTheCellContainsOneLine-ONE-CELL_SELECTED.jsx
                            // Uwe Laubender
                            
                            /**
                            * @@@BUILDINFO@@@ ExpandTheWidthOfColumn-UntilTheCellContainsOneLine-ONE-CELL_SELECTED.jsx !Version! Mon Jan 11 2016 18:24:46 GMT+0100
                            */
                            
                            // WARNING:
                            // YOU CANNOT TRUST THIS SCRIPT WITH OVERSET CELLS
                            
                            // Will expand the width of a cell, until:
                            // 1. There is only the number of lines of text left, that is defined with "wantedLineLength"
                            // OR :
                            // 2. The maximum of iterations is reached.
                            //    See value of variable "maximumNumberOfSingleSteps"
                            
                            // HOW TO USE:
                            // Select a single cell and run the script:
                            
                            
                            // EDIT TO YOUR NEEDS,
                            // PLAY WITH THESE VALUES:
                            
                            var singleStep = 1; // In my InDesign documents the value 1 means 1 millimeter. Your measurement system might vary.
                            var maximumNumberOfSingleSteps = 100;
                            
                            var wantedLineLength = 1;
                            
                            
                            // Do not change something here:
                            
                            var cell = app.selection[0];
                            var counter = 0;
                            var lineLength = cell.lines.length;
                            
                            while(lineLength > wantedLineLength && counter <= maximumNumberOfSingleSteps)
                            {
                                // Not optional. Recompose the table:
                                cell.parentColumn.parent.recompose();
                               
                                // The width of the column of the cell will be made bigger.
                                // Step by step:
                               
                                cell.parentColumn.width = cell.parentColumn.width + singleStep;
                               
                                lineLength = cell.lines.length;
                                counter++;
                               
                            };
                            
                            alert("lineLength"+"\t"+lineLength);
                            

                             

                            If a lot more help is needed, you should order a paid custom script.

                             

                            Uwe

                            • 11. Re: Length of text upto the aligned character
                              aviR Level 1

                              Thank You soo much for the help

                              Thanks