Author Topic: Thousands separator  (Read 210 times)

0 Members and 1 Guest are viewing this topic.

RamiMann

  • Mosquito
  • Posts: 9
Thousands separator
« on: May 27, 2023, 04:30:42 AM »
Hello
I'm looking for a lisp that adds a thousands separator for a selection set of text (not a single text)
Thanks

Beavis

  • Retired
  • Needs a day job
  • Posts: 7904
  • AKA Daniel
Re: Thousands separator
« Reply #1 on: May 27, 2023, 06:42:33 AM »
do you have a sample drawing, is the number embedded with other text?
Retired

RamiMann

  • Mosquito
  • Posts: 9
Re: Thousands separator
« Reply #2 on: May 27, 2023, 07:15:22 AM »
Here's a sample
« Last Edit: May 27, 2023, 08:22:40 AM by RamiMann »

kasmo

  • Mosquito
  • Posts: 16
Re: Thousands separator
« Reply #3 on: May 27, 2023, 05:45:59 PM »
This should work:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / old new ss i j ob sep )
  2.   (setq sep (car (vl-string->list ","))) ;; tausend separator
  3.   (if (setq ss (ssget '((0 . "text"))))
  4.     (repeat (setq j (sslength ss))
  5.       (setq
  6.         i 1
  7.         new nil
  8.         ob (vlax-ename->vla-object (ssname ss (setq j (1- j))))
  9.         old (reverse (vl-string->list (vla-get-textstring ob)))
  10.       )
  11.       (repeat (length old)
  12.         (if
  13.           (and
  14.             (eq (mod i 3) 0)
  15.             (nth i old)
  16.           )
  17.           (setq new (cons sep (cons (nth (1- i) old) new)))
  18.           (setq new (cons (nth (1- i) old) new))
  19.         )
  20.         (setq i (1+ i))
  21.       )
  22.       (vla-put-textstring ob (vl-list->string new))
  23.     )
  24.   )        
  25. )
  26.  
« Last Edit: May 27, 2023, 05:50:03 PM by kasmo »