Author Topic: Thousands separator  (Read 1281 times)

0 Members and 1 Guest are viewing this topic.

RamiMann

  • Mosquito
  • Posts: 11
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

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • 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?

RamiMann

  • Mosquito
  • Posts: 11
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

  • Newt
  • Posts: 28
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 »

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Thousands separator
« Reply #4 on: May 28, 2023, 07:37:39 AM »
This should work:

Code - Auto/Visual Lisp: [Select]
  1. ...
  2. (eq (mod i 3) 0)
  3. ...
  4.  


Code: [Select]
error: no function definition: MOD

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Thousands separator
« Reply #5 on: May 28, 2023, 09:06:25 AM »
rem ?

kasmo

  • Newt
  • Posts: 28
Re: Thousands separator
« Reply #6 on: May 28, 2023, 01:58:56 PM »
This should work:

Code - Auto/Visual Lisp: [Select]
  1. ...
  2. (eq (mod i 3) 0)
  3. ...
  4.  


Code: [Select]
error: no function definition: MOD

What CAD software are you using? Using rem instead of mod like Beavis suggested would probably work.

RamiMann

  • Mosquito
  • Posts: 11
Re: Thousands separator
« Reply #7 on: May 29, 2023, 01:37:27 AM »
It worked perfectly
Thanks a lot

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: Thousands separator
« Reply #8 on: May 29, 2023, 04:05:17 AM »
This should work:

Code - Auto/Visual Lisp: [Select]
  1. ...
  2. (eq (mod i 3) 0)
  3. ...
  4.  


Code: [Select]
error: no function definition: MOD

What CAD software are you using? Using rem instead of mod like Beavis suggested would probably work.
CAD 2021

RamiMann

  • Mosquito
  • Posts: 11
Re: Thousands separator
« Reply #9 on: May 30, 2023, 01:01:37 AM »
It worked perfectly
Thanks a lot