Author Topic: Numeric text lisp  (Read 8339 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #15 on: May 15, 2019, 05:13:16 PM »
Hi  ronjonp. I can not understand it. And the page is not working

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: Numeric text lisp
« Reply #16 on: May 15, 2019, 05:48:15 PM »

Learn to debug.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #17 on: May 15, 2019, 05:52:40 PM »
Hi kdub. I can not understand ?  :idea:

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: Numeric text lisp
« Reply #18 on: May 15, 2019, 06:49:23 PM »
Hi kdub. I can not understand ?  :idea:

What is it that you don't understand ?

added:
other than the way I spell 'be'
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #19 on: May 15, 2019, 06:52:50 PM »
I don't understand what changes should be made

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: Numeric text lisp
« Reply #20 on: May 15, 2019, 07:00:25 PM »
I don't understand what changes should be made

The variables that are global ( not localised to the function ) should be localised so that their value does not carry over for the next iteration of the routine.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:numtext ( / c_doc ms s_no e_no str    CNT C_DOC PFIX PS SFIX SV_LST SV_VALS S_FIX X Y)  ;;; similar to this
  2.  
  3. ;;; >>>>
  4. )


added:
I knew they were global because I checked the code in VLIDE.
Tools » Environment Options » General Options  ->> Diagnostic ->> set 'Toggle Statistics ... ON

Then
Tools » Check Text in Editor
or
Tools » Check Selection

« Last Edit: May 15, 2019, 07:06:12 PM by kdub »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Numeric text lisp
« Reply #21 on: May 15, 2019, 07:28:15 PM »
This solves the errors. One instance of variable "sfix" was incorrectly entered as "s_fix"  :uglystupid2: causing the error only when prefix was the first option selected.

Code - Auto/Visual Lisp: [Select]
  1. (defun rh:get_int (msg / no)
  2.   (initget 7)
  3.   (setq no (getint (strcat "\nEnter " msg " No : ")))
  4. );end_defun  
  5.  
  6. (defun rh:get_kword ( msg lst d_val / tmp)
  7.   (cond ( (and (= (type lst) 'LIST) (vl-position d_val lst) (= (type msg) 'STR))
  8.           (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) lst))))
  9.           (cond ( (setq tmp (getkword (strcat "\n" msg " ["(vl-string-right-trim "/" (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) lst))) "] <" d_val "> : ")))) (d_val))
  10.         )
  11.   );end_cond        
  12. );end_defun
  13.  
  14. (defun rh:get_str ( msg / tmp)
  15.   (cond ( (= (type msg) 'STR) (setq tmp (getstring (strcat "\n" msg " : ")))))
  16. );end_defun
  17.  
  18. (defun c:numtext ( / *error* c_doc ms sv_lst sv_vals ps pfix sfix s_no e_no str cnt)
  19.  
  20.         (defun *error* ( msg )
  21.     (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  22.                 (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  23.                 (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
  24.                 (princ)
  25.         );_end_*error*_defun
  26.  
  27.   (setq sv_lst (list 'dynprompt 'dynmode 'cmdecho)
  28.         sv_vals (mapcar 'getvar sv_lst)
  29.         ps (rh:get_kword "Prefix or Suffix" (list "None" "Prefix" "Suffix" "Both") "None")
  30.   );end_setq
  31.  
  32.   (mapcar 'setvar sv_lst (list 1 3 0))
  33.  
  34.   (cond ( (= ps "Prefix") (setq pfix (rh:get_str "Enter Prefix") sfix ""))
  35.         ( (= ps "Suffix")  (setq sfix (rh:get_str "Enter Suffix") pfix ""))
  36.         ( (= ps "Both")  (setq pfix (rh:get_str "Enter Prefix") sfix (rh:get_str "Enter Suffix")))
  37.         ( (= ps "None") (setq pfix "" sfix ""))
  38.   );end_cond      
  39.  
  40.         ms (vla-get-modelspace c_doc)
  41.         s_no (rh:get_int "Start")
  42.         e_no (rh:get_int "End")
  43.         str (strcat pfix (itoa e_no) sfix " - " pfix (itoa s_no) sfix)
  44.         cnt (1- e_no)
  45.   );end_setq
  46.   (while (< (1- s_no) cnt e_no)
  47.     (setq str (strcat pfix (itoa cnt) sfix " - " str)
  48.           cnt (1- cnt)
  49.     );end_setq
  50.   );end_while
  51.  
  52.   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  53.  
  54.   (vla-addmtext ms (vlax-3d-point (getpoint "\nSelect Insertion Point : ")) 0 str)
  55.  
  56.   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))  
  57.   (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  58. );end_defun
  59.  
« Last Edit: May 15, 2019, 07:34:30 PM by Dlanor »

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #22 on: May 16, 2019, 01:31:38 AM »
thanks Dlanor   :-D :-D :-D :-D

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Numeric text lisp
« Reply #23 on: May 16, 2019, 09:33:59 AM »
I don't understand what changes should be made

Kerry and I tried once again to lead you in the right direction to figure out something for yourself but from past experience with many of your posts ( including this one ), I don't think you really want to learn...  :roll:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #24 on: May 16, 2019, 10:44:46 AM »
Hi ronjonp. All this years i have learned a lot of things. But this explanetion is  easier for me to understand.

Quote
This solves the errors. One instance of variable "sfix" was incorrectly entered as "s_fix"  :uglystupid2: causing the error only when prefix was the first option selected.

Any way ..Thank you all for the help  :-) :-)

PM

  • Guest
Re: Numeric text lisp
« Reply #25 on: November 09, 2019, 04:21:30 AM »
Hi nice code.

Code - Auto/Visual Lisp: [Select]
  1.     (defun rh:get_int (msg / no)
  2.       (initget 7)
  3.       (setq no (getint (strcat "\nEnter " msg " No : ")))
  4.     );end_defun  
  5.      
  6.     (defun rh:get_kword ( msg lst d_val / tmp)
  7.       (cond ( (and (= (type lst) 'LIST) (vl-position d_val lst) (= (type msg) 'STR))
  8.               (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) lst))))
  9.               (cond ( (setq tmp (getkword (strcat "\n" msg " ["(vl-string-right-trim "/" (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) lst))) "] <" d_val "> : ")))) (d_val))
  10.             )
  11.       );end_cond        
  12.     );end_defun
  13.      
  14.     (defun rh:get_str ( msg / tmp)
  15.       (cond ( (= (type msg) 'STR) (setq tmp (getstring (strcat "\n" msg " : ")))))
  16.     );end_defun
  17.      
  18.     (defun c:numtext ( / *error* c_doc ms sv_lst sv_vals ps pfix sfix s_no e_no str cnt)
  19.      
  20.             (defun *error* ( msg )
  21.         (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  22.                     (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  23.                     (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
  24.                     (princ)
  25.             );_end_*error*_defun
  26.      
  27.       (setq sv_lst (list 'dynprompt 'dynmode 'cmdecho)
  28.             sv_vals (mapcar 'getvar sv_lst)
  29.             ps (rh:get_kword "Prefix or Suffix" (list "None" "Prefix" "Suffix" "Both") "None")
  30.       );end_setq
  31.      
  32.       (mapcar 'setvar sv_lst (list 1 3 0))
  33.      
  34.       (cond ( (= ps "Prefix") (setq pfix (rh:get_str "Enter Prefix") sfix ""))
  35.             ( (= ps "Suffix")  (setq sfix (rh:get_str "Enter Suffix") pfix ""))
  36.             ( (= ps "Both")  (setq pfix (rh:get_str "Enter Prefix") sfix (rh:get_str "Enter Suffix")))
  37.             ( (= ps "None") (setq pfix "" sfix ""))
  38.       );end_cond      
  39.      
  40.             ms (vla-get-modelspace c_doc)
  41.             s_no (rh:get_int "Start")
  42.             e_no (rh:get_int "End")
  43.             str (strcat pfix (itoa e_no) sfix " - " pfix (itoa s_no) sfix)
  44.             cnt (1- e_no)
  45.       );end_setq
  46.       (while (< (1- s_no) cnt e_no)
  47.         (setq str (strcat pfix (itoa cnt) sfix " - " str)
  48.               cnt (1- cnt)
  49.         );end_setq
  50.       );end_while
  51.      
  52.       (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  53.       (vla-startundomark c_doc)
  54.      
  55.       (vla-addmtext ms (vlax-3d-point (getpoint "\nSelect Insertion Point : ")) 0 str)
  56.      
  57.       (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))  
  58.       (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  59.     );end_defun
  60.      
  61.  


Can any one  add an option to do the oposite

to insert a text  (10 - 9 - 8 - 7 - 6  - 5 - 4 - 3 - 2 - 1 - 10)

for example

1) insert text  (1 - 2 - 3 - ....-1)
2) insert text  (10 - 9 - 8 - ....- 1 -10)

Thanks

Dlanor

  • Bull Frog
  • Posts: 263
Re: Numeric text lisp
« Reply #26 on: November 09, 2019, 03:15:25 PM »
Try this briefly tested, positive numbers only.

Code - Auto/Visual Lisp: [Select]
  1. (defun rh:get_int (msg / no)
  2.   (initget 7)
  3.   (setq no (getint (strcat "\nEnter " msg " No : ")))
  4. );end_defun
  5.  
  6. (defun rh:get_kword ( msg lst d_val / tmp)
  7.   (cond ( (and (= (type lst) 'LIST) (vl-position d_val lst) (= (type msg) 'STR))
  8.           (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) lst))))
  9.           (cond ( (setq tmp (getkword (strcat "\n" msg " ["(vl-string-right-trim "/" (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) lst))) "] <" d_val "> : ")))) (d_val))
  10.         )
  11.   );end_cond
  12. );end_defun
  13.  
  14. (defun rh:get_str ( msg / tmp)
  15.   (cond ( (= (type msg) 'STR) (setq tmp (getstring (strcat "\n" msg " : ")))))
  16. );end_defun
  17.  
  18. (defun c:numtext ( / *error* c_doc ms sv_lst sv_vals ps pfix sfix s_no e_no str cnt)
  19.  
  20.   (defun *error* ( msg )
  21.     (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  22.     (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
  23.     (princ)
  24.   );_end_*error*_defun
  25.  
  26.   (setq sv_lst (list 'dynprompt 'dynmode 'cmdecho)
  27.         sv_vals (mapcar 'getvar sv_lst)
  28.         ps (rh:get_kword "Prefix or Suffix" (list "None" "Prefix" "Suffix" "Both") "None")
  29.   );end_setq
  30.  
  31.   (mapcar 'setvar sv_lst (list 1 3 0))
  32.  
  33.   (cond ( (= ps "Prefix") (setq pfix (rh:get_str "Enter Prefix") sfix ""))
  34.         ( (= ps "Suffix")  (setq sfix (rh:get_str "Enter Suffix") pfix ""))
  35.         ( (= ps "Both")  (setq pfix (rh:get_str "Enter Prefix") sfix (rh:get_str "Enter Suffix")))
  36.         ( (= ps "None") (setq pfix "" sfix ""))
  37.   );end_cond
  38.  
  39.         ms (vla-get-modelspace c_doc)
  40.         s_no (rh:get_int "Start")
  41.         e_no (rh:get_int "End")
  42.         str (strcat pfix (itoa e_no) sfix " - " pfix (itoa s_no) sfix)
  43.   );end_setq
  44.  
  45.   (cond ( (> e_no s_no)
  46.           (setq cnt (1- e_no))
  47.           (while (< (1- s_no) cnt e_no)
  48.             (setq str (strcat pfix (itoa cnt) sfix " - " str)
  49.                   cnt (1- cnt)
  50.             );end_setq
  51.           );end_while
  52.         )
  53.         (t
  54.           (setq cnt (1+ e_no))
  55.           (while (> (1+ s_no) cnt e_no)
  56.             (setq str (strcat pfix (itoa cnt) sfix " - " str)
  57.                   cnt (1+ cnt)
  58.             );end_setq
  59.           );end_while
  60.         )
  61.   );end_cond
  62.  
  63.   (vla-addmtext ms (vlax-3d-point (getpoint "\nSelect Insertion Point : ")) 0 str)
  64.  
  65.   (mapcar '(lambda (x y) (setvar x y)) sv_lst sv_vals)
  66. );end_defun
  67.  
  68.  

PM

  • Guest
Re: Numeric text lisp
« Reply #27 on: November 09, 2019, 05:28:36 PM »
Hi Dlanor. Thank you for the update !!