Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Figure spacing script/plugin?

Return to Member Forum

  • Author
    Posts
    • #56634
      Anonymous
      Inactive

      Hi, has anyone seen a script or plugin that can add the correct number of figure spaces to each cell in the selected column or columns?

      I suppose it would have to determine the longest number (integers only?) in each column and add leading figure spaces cell by cell.

      If this isn't reinventing the wheel, how would I go about scripting it? Given all the dimensions tables in the product catalogues I publish, it would save me hours a week.

      Thanks,

      David Harrison

    • #56635
      David Blatner
      Keymaster

      Why are you adding figure spaces? That sounds terrible! I would recommend using tabs, which can automatically align numbers for you. See this post:

      https://creativepro.com/tab…..tables.php

    • #56636
      Anonymous
      Inactive

      I know what you mean, and use it for other purposes, but…tabs make sense if the columns are likely to stay the same width! If they change regularly (and with my client they do, all the time as stuff is added, deleted or borrowed from elsewhere), then you have to adjust the tab placements accordingly.

      Figure spaces + centred text (+ integer values!) means that you can change column width as often as you like and the centred columns adjust gracefully, no changes required to tab values.

    • #56649

      I agree with you both: if I can, I select an entire column and set a decimal tab. But there are occasions where I opt for Figure spaces — I even assigned a hotkey to it.

      This script has been in the making for some time, because usually when I only have to align 1 or 2 numbers (or 3 or 4 or …), I set my mind on Blank and go moovin' that ol' cursor around an' hittin' the Figure Space shortcut, but all the while I'm thinking “hold on, there's got to be a better way”.

      Surprisingly, this script is quite versatile: you can select any number of cells, horizontally, vertically, or even an entire Table. It uses a tiny GREP instruction to count the number of leading digits, so it will ignore anything that may come after it (such as decimal points, percentage signs, or a text such as “bottles of beer”). The longest decimal run count is saved, then it loops again over your selection, counting the digits that are in each cell and inserting Figure Spaces at the start to match the longest run.

      Copy, paste into the ESTK Editor that came with InDesign. Save into your User Scripts folder, select any number of cells, then run the script:

      //DESCRIPTION:Align Digits in Selected Column(s) in Table with Figure Spaces
      // 11-Aug-2010 A Jongware Script
      if (app.documents.length > 0 && app.selection.length == 1 && (app.selection[0] instanceof Column || app.selection[0] instanceof Cell || app.selection[0] instanceof Row || app.selection[0] instanceof Table))
      {
      txt = app.selection[0].cells.everyItem().contents;
      longest = 0;
      for (i=0; i<txt.length; i++)
      {
      nspan = txt[i].match(/^d+/);
      if (!nspan) continue;
      if (nspan[0].length > longest)
      longest = nspan[0].length;
      }
      for (i=0; i<txt.length; i++)
      {
      nspan = txt[i].match(/^d+/);
      if (!nspan) continue;
      add = longest-nspan[0].length;
      while (add– > 0)
      app.selection[0].cells[i].texts[0].insertionPoints[0].contents = SpecialCharacters.FIGURE_SPACE;
      }
      } else
      alert (“No table column(s) selected”);

    • #56650
      Anonymous
      Inactive

      Wow, thanks, that's above and beyond the call! I will try that out tomorrow on the next batch and report back.

    • #56652
      Anonymous
      Inactive

      Hmmm… there was a syntax error at about line 19 according to my editor, around the part it says

      add- > 0

      . I tried changing that to both

      add > 0

      and

      add– > 0

      and the script ran both times, but nothing visible happened in ID! I'm probably missing something glaringly obvious but sadly I don't know Javascript very well.

      ('scuse the dodgy post formatting, but it doesn't seem to handle the HTML 'pre' tag very well!)

    • #56655

      Eh!

      That should be “add hyphen hyphen”, not “add en-dash” (!).

    • #56656
      David Blatner
      Keymaster

      Yes, once again code is messed up by our forum software trying to be helpful. Two hyphens get converted automatically. Sorry.

      (Aren't you happy that you don't have to write a lot of colon-paren and semi-colon-parentheses in your code? They'd all get converted to smileys. :)

    • #56657
      Anonymous
      Inactive

      Thanks for the correction! Sadly I tried the add minus minus edit and it still doesn't add any figure spaces. Am I missing anything else?

    • #56659

      Not minus, use hyphens. But perhaps something else got formatted nicely :)

      I've put the script onto my website: AlignNumbers.jsx — Download from there and save as “alignNumbers.jsx” into your Scripts folder (etc.); then, if it still fails it must be Some Other Error. I wrote & tested it using CS4, but I don't think there is something to make either CS3 or CS5 trip over.

    • #56660
      Anonymous
      Inactive

      It works! Now I have to resist the tempation to go looking for excuses to use the script — sure as eggs is eggs one will crop up later today.

      It's quite fun typing a keyboard shortcut and watching a few long columns of numbers pop into place.

      Thank you very much. You've made an old user very happy. I'm buying the beer if you find yourself in this bit of the UK!

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
Forum Ads