Author Topic: Numeric text lisp  (Read 1392 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: 175
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: 346
  • 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: 175
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: 175
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: 7044
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: 7044
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