TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: RamiMann on May 27, 2023, 04:30:42 AM

Title: Thousands separator
Post by: RamiMann 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
Title: Re: Thousands separator
Post by: It's Alive! on May 27, 2023, 06:42:33 AM
do you have a sample drawing, is the number embedded with other text?
Title: Re: Thousands separator
Post by: RamiMann on May 27, 2023, 07:15:22 AM
Here's a sample
Title: Re: Thousands separator
Post by: kasmo 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.  
Title: Re: Thousands separator
Post by: HasanCAD 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
Title: Re: Thousands separator
Post by: It's Alive! on May 28, 2023, 09:06:25 AM
rem ?
Title: Re: Thousands separator
Post by: kasmo 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.
Title: Re: Thousands separator
Post by: RamiMann on May 29, 2023, 01:37:27 AM
It worked perfectly
Thanks a lot
Title: Re: Thousands separator
Post by: HasanCAD 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
Title: Re: Thousands separator
Post by: RamiMann on May 30, 2023, 01:01:37 AM
It worked perfectly
Thanks a lot