Author Topic: Numeric text lisp  (Read 1733 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Numeric text lisp
« on: March 19, 2019, 06:24:40 PM »
Hi i have to decride with numbers multiple big areas like this

Code: [Select]
1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 - 38 - 39 - 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 - 48 - 49 - 50 - 51 - 52 - 53 - 54 - 55 - 56 - 57 - 58 - 59 - 60 - 61 - 62 - 63 - 64 - 65 - 66 - 67 - 68 - 69 - 70 - 71 - 72 - 73 - 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 - 84 - 85 - 86 - 87 - 88 - 89 - 90 - 91 - 92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 - 100 - 101 - 102 - 103 - 104 - 105 - 106 - 107 - 108 - 109 - 110 - 111 - 112 - 113 - 114 - 115 - 116 - 117 - 118 - 119 - 120 - 121 - 122 - 123 - 124 - 125 - 126 - 127 - 128 - 129 - 130 - 131 - 132 - 133 - 134 - 135 - 136 - 137 - 138 - 139 - 140 - 141 - 142 - 143 - 144 - 145 - 146 - 147 - 148 - 149 - 150 - 151 - 152 - 153 - 154 - 155 - 156 - 157 - 158 - 159 - 160 - 161 - 162 - 163 - 164 - 165 - 166 - 167 - 168 - 169 - 170 - 171 - 172 - 173 - 174 - 175 - 176 - 177 - 178 - 179 - 180 - 181 - 182 - 183 - 184 - 185 - 186 - 187 - 188 - 189 - 190 - 191 - 192 - 193 - 194 - 195 - 196  - 197 - 198 - 199 - 200 - 201 - 202 - 203 - 204 - 205 - 206 - 207 - 208 - 209 - 210 - 211 - 212 - 213 - 214 - 215 - 216 - 217 - 218 - 219 - 220 - 221 - 222 - 223 - 224 - 225 - 226 - 227 - 228 - 229 - 230 - 231 - 232 - 233 - 234 - 235 - 236 - 237 - 238 - 1 = 6052.57 sq.m

The problem is that i have to write  all this numers.

Is it possible to write them with a lisp
for examle

1. Give the first mumber :
2)Give the last number :

if the first number is 92 and the last is 194  write  a  mtext like this
Code: [Select]
92 - 93 - 94 - 95 - 96 - 97 - 98 - 99 - 100 - 101 - 102 - 103 - 104 - 105 - 106 - 107 - 108 - 109 - 110 - 111 - 112 - 113 - 114 - 115 - 116 - 117 - 118 - 119 - 120 - 121 - 122 - 123 - 124 - 125 - 126 - 127 - 128 - 129 - 130 - 131 - 132 - 133 - 134 - 135 - 136 - 137 - 138 - 139 - 140 - 141 - 142 - 143 - 144 - 145 - 146 - 147 - 148 - 149 - 150 - 151 - 152 - 153 - 154 - 155 - 156 - 157 - 158 - 159 - 160 - 161 - 162 - 163 - 164 - 165 - 166 - 167 - 168 - 169 - 170 - 171 - 172 - 173 - 174 - 175 - 176 - 177 - 178 - 179 - 180 - 181 - 182 - 183 - 184 - 185 - 186 - 187 - 188 - 189 - 190 - 191 - 192 - 193 - 194 - 92

Thanks

Dlanor

  • Newt
  • Posts: 183
Re: Numeric text lisp
« Reply #1 on: March 19, 2019, 06:56:27 PM »
Pretty basic, but works.

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 c:numtext ( / c_doc ms s_no e_no str)
  7.  
  8.         ms (vla-get-modelspace c_doc)
  9.         s_no (rh:get_int "Start")
  10.         e_no (rh:get_int "End")
  11.         str (strcat (itoa e_no) " - " (itoa s_no))
  12.         cnt (1- e_no)
  13.   );end_setq
  14.   (while (< (1- s_no) cnt e_no)
  15.     (setq str (strcat (itoa cnt) " - " str)
  16.           cnt (1- cnt)
  17.     );end_setq
  18.   );end_while
  19.   (vla-addmtext ms (vlax-3d-point (getpoint "\nSelect Insertion Point : ")) 0 str)
  20. );end_defun
  21.  

BIGAL

  • Bull Frog
  • Posts: 359
  • 30 + years of using Autocad
Re: Numeric text lisp
« Reply #2 on: March 20, 2019, 01:18:08 AM »
Dlanor maybe an extra question 1 line or column if column add the \\p can just see that being next question.

Have a look at this for multiple entry
A man who never made a mistake never made anything

kirby

  • Newt
  • Posts: 32
Re: Numeric text lisp
« Reply #3 on: March 20, 2019, 09:23:50 AM »
BigAl - Very nice, efficient method of collecting a lot of data.

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #4 on: March 20, 2019, 03:19:15 PM »
Thank you Dlanor

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #5 on: May 13, 2019, 09:18:26 AM »
Ηι Dlanor. Is it pissible to add prefix and suffix ?

Thanks

Dlanor

  • Newt
  • Posts: 183
Re: Numeric text lisp
« Reply #6 on: May 13, 2019, 03:07:12 PM »
You'll need to be more specific or provide an example of how the new proposed string looks.

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #7 on: May 13, 2019, 04:09:06 PM »
for example

D1 - D2 - D3 - D4 - D1   or  1D  - 2D - 3D - 4D - 1D or D1K - D2K - D3K - D4K - D1K

if i don't have prefix and suffix stay the same

1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 1

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1365
  • class keyThumper<T>:ILazy<T>
Re: Numeric text lisp
« Reply #8 on: May 13, 2019, 05:47:37 PM »

How about :

Provide the ability to include an optional prefix and/or suffix to each number in the set.


called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #9 on: May 14, 2019, 02:22:27 AM »
hi  kdub. I think we say the same thing . I want to have an option to add prefix and suffix. The most of the times i dont use prefix and suffix ,but some times i need this option.

Thanks

Dlanor

  • Newt
  • Posts: 183
Re: Numeric text lisp
« Reply #10 on: May 14, 2019, 03:10:24 PM »
try this updated lisp, minimally tested as I'm completely knackered and off to bed.

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 s_no e_no str)
  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") s_fix ""))
  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.  
  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.   (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark 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.  

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #11 on: May 14, 2019, 05:08:59 PM »
Nice job Dlanor. Is it possible to add a text wrapping after 26 numbers because if i add numbers from 1 to 100 the text is too long   :-D .

Thanks

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Numeric text lisp
« Reply #12 on: May 14, 2019, 06:06:47 PM »
Nice job Dlanor. Is it possible to add a text wrapping after 26 numbers because if i add numbers from 1 to 100 the text is too long   :-D .

Thanks
All you need to do is change the width of the mtext and it will wrap?

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

pedroantonio

  • Guest
Re: Numeric text lisp
« Reply #13 on: May 15, 2019, 10:43:12 AM »
hI  Dlanor i find a bug in the code

a) When i run first time the code and  give for example  Prefix D and first number 1 and last number 10 gives me thiis error text

Quote
Oops an Error : bad argument type: stringp nil occurred.

I dont't know why ???

b) After this error if i give  Suffix D and first number 1 and last number 10 print

Quote
1D - 2D - 3D - 4D - 5D - 6D - 7D - 8D - 9D - 10D - 1D

c) Then i try the fist text again and give Prefix D and first number 1 and last number 10 and then print

Quote
D1D - D2D - D3D - D4D - D5D - D6D - D7D - D8D - D9D - D10D - D1D

Why didn't clear the Suffix from the memory ?

Any ideas ?

Thanks

ronjonp

  • Needs a day job
  • Posts: 7060
Re: Numeric text lisp
« Reply #14 on: May 15, 2019, 11:21:41 AM »
Quote
D1D - D2D - D3D - D4D - D5D - D6D - D7D - D8D - D9D - D10D - D1D

Why didn't clear the Suffix from the memory ?

Any ideas ?

Thanks

Take a look into localizing variables.
http://www.lee-mac.com/quicklocalising.html

Hint:
Code - Auto/Visual Lisp: [Select]
  1. ; === Top statistic:
  2. ; Global variables: (CNT C_DOC PFIX PS SFIX SV_LST SV_VALS S_FIX X Y)
  3. ; Function definition (with number of arguments): ((*ERROR* . 1) (C:NUMTEXT . 0))
  4. ; Check done.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

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

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1365
  • 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

Sometimes the question is more important than the answer.
#ridesober

pedroantonio

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

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1365
  • 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

Sometimes the question is more important than the answer.
#ridesober

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

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1365
  • 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

Sometimes the question is more important than the answer.
#ridesober

Dlanor

  • Newt
  • Posts: 183
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: 7060
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 10 x64 - AutoCAD /C3D 2020

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

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

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

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