TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Krushert on January 07, 2011, 01:21:03 PM

Title: Is there something better than vl-string-subst?
Post by: Krushert on January 07, 2011, 01:21:03 PM
I have more crashes with vl-string-subst function because it looking for a specific value.  I really do not care what the value is or where it is located.  I just want to swap out the last folder name for the new folder name.  Is there a better function or can I reconfigure the mess below.

OLD   :// server //Some spiraling downward path of folders // drawings folder // XYZ-file  This never has a consistent folder name or path.
NEW  :// server //Some spiraling downward path of folders // transfer-outgoing-folder // XYZ-file


Code: [Select]
(defun StrPath (/ CTABNAME NewDwgPreFix OldDwgPreFix)

  (setq CTABNAME (getvar "ctab"))
  (setq OldDwgPreFix (getvar "dwgprefix"))
; Extracts the Drawing Location
  (setq NewDwgPreFix
(vl-string-subst ; Swaps folders from teh existing path
  "\\Transfer-Outgoing\\"
  "\\Drawings\\"    [color=red]<== I really do not care what this folder is named[/color][/b]
  OldDwgPreFix
)
  )

  (today) ; Calls the Today's Date Sub-Function

  (setq NewFileName (strcat NewDwgPreFix Dates CTABNAME))
; Text String for New File Name

  (vl-mkdir NewDwgPreFix) ; checks to see if new folder is present and if not creates.
  (princ)
)
Title: Re: Is there something better than vl-string-subst?
Post by: Lee Mac on January 07, 2011, 01:30:09 PM
Something along these lines?

Code: [Select]
(defun StrPath ( / path )

  (setq path (vl-string-translate "/" "\\" (getvar 'DWGPREFIX)))

  (if (eq "\\" (substr path (strlen path)))
    (setq path (substr path 1 (1- (strlen path))))
  )

  (setq path (strcat (substr path 1 (vl-string-position 92 path nil t)) "\\Transfer-Outgoing\\"))
  (vl-mkdir path)
  (princ)
)
Title: Re: Is there something better than vl-string-subst?
Post by: Krushert on January 07, 2011, 02:23:39 PM
OKay I see what you are doing, A little bit.  Thanks

How does 92 play in with the vl-string-position?
Title: Re: Is there something better than vl-string-subst?
Post by: ronjonp on January 07, 2011, 02:25:58 PM
OKay I see what you are doing, A little bit.  Thanks

How does 92 play in with the vl-string-position?

Hint:

Command: (chr 92)
"\\"
Title: Re: Is there something better than vl-string-subst?
Post by: Krushert on January 07, 2011, 03:01:19 PM
OKay I see what you are doing, A little bit.  Thanks

How does 92 play in with the vl-string-position?

Hint:

Command: (chr 92)
"\\"

Aha!  Where does one find the secrete decoder ring for these numbers? 
Title: Re: Is there something better than vl-string-subst?
Post by: ronjonp on January 07, 2011, 03:17:32 PM
Try something like this:

Code: [Select]
(defun c:getascii (/ x)
  (while (and (setq x (grread)) (/= (car x) 3))
    (princ "\rPress a key any key ... pick a point to exit loop")
    (and (= (car x) 2) (alert (strcat (chr (cadr x)) " = " (itoa (cadr x)))))
  )
)
(c:getascii)
Title: Re: Is there something better than vl-string-subst?
Post by: MP on January 07, 2011, 03:58:36 PM
fwiw ... a quick & dirty little proggy:

Code: [Select]
(defun c:ASCII ( / _rset _chr spacer1 spacer2 i j k )

    (defun _rset ( x len )
        (setq x (vl-princ-to-string x))
        (while (< (strlen x) len)
            (setq x (strcat " " x))
        )
        x
    )
   
    (defun _chr ( code )
        (if (member code '(129 141 143 144 157 160 173))
            " "
            (chr code)
        )
    )

    (setq
        i        31
        spacer1  " "
        spacer2  "        "
    )
   
    (princ "Codes 1 to 31 are control codes, some notable ones:\n\n")
   
    (princ
        (strcat
            "  7 bell\n"
            "  9 tab\n"
            " 10 line feed\n"
            " 13 carriage return\n"
            " 27 escape\n\n"
        )
    )
   
    (princ "7 Bit ASCII codes:\n\n")
   
    (repeat 32
        (setq i (1+ i) j -32)
        (repeat 3
            (princ
                (strcat
                    (_rset (setq k (+ i (setq j (+ j 32)))) 3)
                    spacer1
                    (_chr k)
                    spacer2
                )
            )
        )   
        (princ "\n")
    )
   
    (princ "\nExtended ASCII codes:\n\n")
   
    (setq i 127 spacer2 "    ")
   
    (repeat 16
        (setq i (1+ i) j -16)
        (repeat 8
            (princ
                (strcat
                    (_rset (setq k (+ i (setq j (+ j 16)))) 3)
                    spacer1
                    (_chr k)
                    spacer2
                )
            )
        )
        (princ "\n")
    )   

    (princ)
   
)

Prints out:

Code: [Select]
ASCII Codes 1 to 31 are control codes, some notable ones:

  7 bell
  9 tab
 10 line feed
 13 carriage return
 27 escape

7 Bit ASCII codes:

 32           64 @         96 `
 33 !         65 A         97 a
 34 "         66 B         98 b
 35 #         67 C         99 c
 36 $         68 D        100 d
 37 %         69 E        101 e
 38 &         70 F        102 f
 39 '         71 G        103 g
 40 (         72 H        104 h
 41 )         73 I        105 i
 42 *         74 J        106 j
 43 +         75 K        107 k
 44 ,         76 L        108 l
 45 -         77 M        109 m
 46 .         78 N        110 n
 47 /         79 O        111 o
 48 0         80 P        112 p
 49 1         81 Q        113 q
 50 2         82 R        114 r
 51 3         83 S        115 s
 52 4         84 T        116 t
 53 5         85 U        117 u
 54 6         86 V        118 v
 55 7         87 W        119 w
 56 8         88 X        120 x
 57 9         89 Y        121 y
 58 :         90 Z        122 z
 59 ;         91 [        123 {
 60 <         92 \        124 |
 61 =         93 ]        125 }
 62 >         94 ^        126 ~
 63 ?         95 _        127 

Extended ASCII codes:

128 €    144      160      176 °    192 À    208 Ð    224 à    240 ð
129      145 ‘    161 ¡    177 ±    193 Á    209 Ñ    225 á    241 ñ
130 ‚    146 ’    162 ¢    178 ²    194 Â    210 Ò    226 â    242 ò
131 ƒ    147 “    163 £    179 ³    195 Ã    211 Ó    227 ã    243 ó
132 „    148 ”    164 ¤    180 ´    196 Ä    212 Ô    228 ä    244 ô
133 …    149 •    165 ¥    181 µ    197 Å    213 Õ    229 å    245 õ
134 †    150 –    166 ¦    182 ¶    198 Æ    214 Ö    230 æ    246 ö
135 ‡    151 —    167 §    183 ·    199 Ç    215 ×    231 ç    247 ÷
136 ˆ    152 ˜    168 ¨    184 ¸    200 È    216 Ø    232 è    248 ø
137 ‰    153 ™    169 ©    185 ¹    201 É    217 Ù    233 é    249 ù
138 Š    154 š    170 ª    186 º    202 Ê    218 Ú    234 ê    250 ú
139 ‹    155 ›    171 «    187 »    203 Ë    219 Û    235 ë    251 û
140 Œ    156 œ    172 ¬    188 ¼    204 Ì    220 Ü    236 ì    252 ü
141      157      173      189 ½    205 Í    221 Ý    237 í    253 ý
142 Ž    158 ž    174 ®    190 ¾    206 Î    222 Þ    238 î    254 þ
143      159 Ÿ    175 ¯    191 ¿    207 Ï    223 ß    239 ï    255 ÿ

Edit: Revised code a bit to slay a cockroach.
Title: Re: Is there something better than vl-string-subst?
Post by: Krushert on January 07, 2011, 04:11:00 PM
Thanks,   I will try to remember where these decoder rings are buried.   :-)
Title: Re: Is there something better than vl-string-subst?
Post by: Kerry on January 07, 2011, 04:14:57 PM
Quote from: my slumber was rudely interupted by MP
fwiw ... a quick & dirty little proggy:

An excellent example of taking a problem and providing an economical solution with style.



Title: Re: Is there something better than vl-string-subst?
Post by: MP on January 07, 2011, 04:39:11 PM
:)

Have to do lisp here and there while I study Python lest I lose valuable lispin' skills.

Thanks for the kind words KB.
Title: Re: Is there something better than vl-string-subst?
Post by: ronjonp on January 07, 2011, 04:50:36 PM
Michael .. .your "quickly" penned stuff is leaps and bounds better than my thought out code  :-D

Here's a list from 33 - 255.
 
Code: [Select]
33     !
34     "
35     #
36     $
37     %
38     &
39     '
40     (
41     )
42     *
43     +
44     ,
45     -
46     .
47     /
48     0
49     1
50     2
51     3
52     4
53     5
54     6
55     7
56     8
57     9
58     :
59     ;
60     <
61     =
62     >
63     ?
64     @
65     A
66     B
67     C
68     D
69     E
70     F
71     G
72     H
73     I
74     J
75     K
76     L
77     M
78     N
79     O
80     P
81     Q
82     R
83     S
84     T
85     U
86     V
87     W
88     X
89     Y
90     Z
91     [
92     \
93     ]
94     ^
95     _
96     `
97     a
98     b
99     c
100     d
101     e
102     f
103     g
104     h
105     i
106     j
107     k
108     l
109     m
110     n
111     o
112     p
113     q
114     r
115     s
116     t
117     u
118     v
119     w
120     x
121     y
122     z
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     î
239     ï
240     ð
241     ñ
242     ò
243     ó
244     ô
245     õ
246     ö
247     ÷
248     ø
249     ù
250     ú
251     û
252     ü
253     ý
254     þ
255     ÿ
Title: Re: Is there something better than vl-string-subst?
Post by: CAB on January 07, 2011, 06:42:20 PM
And after 20 years I'm still using this:  :-D

Title: Re: Is there something better than vl-string-subst?
Post by: David Bethel on January 08, 2011, 06:08:43 AM
I still like this 1:

http://www.asciitable.com/ (http://www.asciitable.com/)

I use the html and hex values as well.  -David
Title: Re: Is there something better than vl-string-subst?
Post by: MP on January 08, 2011, 09:15:46 AM
Version 2, dumbed down / simplified:

Code: [Select]
(defun c:ASCII ( / _lset _rset _chr _main )

    (defun _lset ( x len )
        (setq x (vl-princ-to-string x))
        (while (< (strlen x) len)
            (setq x (strcat x " "))
        )
        x
    )
   
    (defun _rset ( x len )
        (setq x (vl-princ-to-string x))
        (while (< (strlen x) len)
            (setq x (strcat " " x))
        )
        x
    )
   
    (defun _chr ( code / char len )
        (setq len 6)
        (strcat " "
            (cond
                (   (setq char
                        (nth code
                           '("NUL" "SOH" "STX" "ETX" "EOT" "ENQ" "ACK" "BEL"
                             "BS"  "TAB" "LF"  "VT"  "FF"  "CR"  "SO"  "SI"
                             "DLE" "DC1" "DC2" "DC3" "DC4" "NAK" "SYN" "ETB"
                             "CAN" "EM"  "SUB" "ESC" "FS"  "GS"  "RS"  "US" "SPC")
                        )
                    )
                    (_lset char len)
                )   
                (   (member code '(127 129 141 143 144 157 160 173))
                    (_lset " " len)
                )
                (   t
                    (_lset (chr code) len)
                )
            )
        )       
    )
   
    (defun _main ( / i j k )

        (setq i -1)

        (repeat 32
            (setq i (1+ i) j -32)
            (princ "\n")
            (repeat 8
                (princ
                    (strcat
                        (_rset (setq k (+ i (setq j (+ j 32)))) 3)
                        (_chr k)
                    )
                )
            )   
        )

        (princ)
       
    )
   
    (_main)
   
)

Output:

Code: [Select]
  0 NUL    32 SPC    64 @      96 `     128 €     160       192 À     224 à
  1 SOH    33 !      65 A      97 a     129       161 ¡     193 Á     225 á
  2 STX    34 "      66 B      98 b     130 ‚     162 ¢     194      226 â
  3 ETX    35 #      67 C      99 c     131 ƒ     163 £     195 à    227 ã
  4 EOT    36 $      68 D     100 d     132 „     164 ¤     196 Ä     228 ä
  5 ENQ    37 %      69 E     101 e     133 …     165 ¥     197 Å     229 å
  6 ACK    38 &      70 F     102 f     134 †     166 ¦     198 Æ     230 æ
  7 BEL    39 '      71 G     103 g     135 ‡     167 §     199 Ç     231 ç
  8 BS     40 (      72 H     104 h     136 ˆ     168 ¨     200 È     232 è
  9 TAB    41 )      73 I     105 i     137 ‰     169 ©     201 É     233 é
 10 LF     42 *      74 J     106 j     138 Š     170 ª     202 Ê     234 ê
 11 VT     43 +      75 K     107 k     139 ‹     171 «     203 Ë     235 ë
 12 FF     44 ,      76 L     108 l     140 Œ     172 ¬     204 Ì     236 ì
 13 CR     45 -      77 M     109 m     141       173       205 Í     237 í
 14 SO     46 .      78 N     110 n     142 Ž     174 ®     206 Π    238 î
 15 SI     47 /      79 O     111 o     143       175 ¯     207 Ï     239 ï
 16 DLE    48 0      80 P     112 p     144       176 °     208 Р    240 ð
 17 DC1    49 1      81 Q     113 q     145 ‘     177 ±     209 Ñ     241 ñ
 18 DC2    50 2      82 R     114 r     146 ’     178 ²     210 Ò     242 ò
 19 DC3    51 3      83 S     115 s     147 “     179 ³     211 Ó     243 ó
 20 DC4    52 4      84 T     116 t     148 ”     180 ´     212 Ô     244 ô
 21 NAK    53 5      85 U     117 u     149 •     181 µ     213 Õ     245 õ
 22 SYN    54 6      86 V     118 v     150 –     182 ¶     214 Ö     246 ö
 23 ETB    55 7      87 W     119 w     151 —     183 ·     215 ×     247 ÷
 24 CAN    56 8      88 X     120 x     152 ˜     184 ¸     216 Ø     248 ø
 25 EM     57 9      89 Y     121 y     153 ™     185 ¹     217 Ù     249 ù
 26 SUB    58 :      90 Z     122 z     154 š     186 º     218 Ú     250 ú
 27 ESC    59 ;      91 [     123 {     155 ›     187 »     219 Û     251 û
 28 FS     60 <      92 \     124 |     156 œ     188 ¼     220 Ü     252 ü
 29 GS     61 =      93 ]     125 }     157       189 ½     221 Ý     253 ý
 30 RS     62 >      94 ^     126 ~     158 ž     190 ¾     222 Þ     254 þ
 31 US     63 ?      95 _     127       159 Ÿ     191 ¿     223 ß     255 ÿ
Title: Re: Is there something better than vl-string-subst?
Post by: MP on January 08, 2011, 09:47:55 AM
If you have DOS Lib (if you don't, dude, wtf) this is hard to beat (pick whatever graphic suits you from the multitudes on the net):

(defun c:ASCII ( )
    (dos_htmlbox
        "Standard ASCII Codes"
        "http://www.tvdsb.ca/webpages/herbertj/files/ASCII1.GIF"
    )
    (princ)
)

(http://i51.tinypic.com/rc7a6q.jpg)

An aside, most IDEs / text editors have built in ASCII charts, Textpad, UltraEdit ...
Title: Re: Is there something better than vl-string-subst?
Post by: Lee Mac on January 08, 2011, 10:32:43 AM
I mostly use this (http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters), or just a quick chr/ascii at the console is usually quickest.
Title: Re: Is there something better than vl-string-subst?
Post by: pBe on January 14, 2011, 11:51:40 PM
fwiw ... a quick & dirty little proggy:

MP
can you write a python version of this code and post it on General Programming board  :-)
Title: Re: Is there something better than vl-string-subst?
Post by: MP on January 15, 2011, 01:35:27 AM
MP
can you write a python version of this code and post it on General Programming board  :-)

there ya go (http://www.theswamp.org/index.php?topic=36674.0)  :-)
Title: Re: Is there something better than vl-string-subst?
Post by: pBe on January 15, 2011, 04:38:23 AM
MP
can you write a python version of this code and post it on General Programming board  :-)

there ya go (http://www.theswamp.org/index.php?topic=36674.0)  :-)

Thank you kind sir  :-)
Title: Re: Is there something better than vl-string-subst?
Post by: cmwade77 on January 18, 2011, 02:19:57 PM
Here's where I find mine:
http://www.asciitable.com/
Title: Re: Is there something better than vl-string-subst?
Post by: GDF on January 18, 2011, 03:25:49 PM
here's an oldie
Code: [Select]
;;;CHARACTR.lsp by Jeff Foster 01/17/96
;;;Recommended that this routine be run in a blank drawing
;;;This routine generates 16 columns and 16 rows of text
;;;consisting of each of the 256 %% characters available
;;;in a particular font and numbers each character.
;;;Modified by Gary Fowler  07/30/99
(Defun c:CHARACTR ()
  (setq cnt 1.0)
  (setq r_cnt 0.0)
  (setq x 0.0)
  (setq y 0.0)
  (setq sub_y (- y 0.1))
  (command "layer" "m" "textfont" "c" "4" "" "")
  (setvar "osmode" 0)
  (repeat 16
    (while (<= (fix cnt) (+ r_cnt 16))
      (setq pt (list x y))
      (setq sub_pt (list x sub_y))
      (command "text"
       "m"
       pt
       "0.05"
       "0"
       (strcat "%%" (rtos cnt 2 0))
      )
      (command "text" "m" sub_pt "0.05" "0" (rtos cnt 2 0))
      (setq x (+ x 0.2))
      (setq cnt (+ cnt 1.0))
    )
    (setq r_cnt (+ r_cnt 16))
    (setq x 0)
    (setq y (- y 0.2))
    (setq sub_y (- y 0.1))
  )
;;;(cdr (assoc 3 (tblsearch "STYLE" (cdr (assoc 7 (entget (car (entsel))))))))
  (setq
    fontnam (cdr
      (assoc
3
(tblsearch "STYLE" (cdr (assoc 7 (entget (entlast)))))
      )
    )
  )
  (name_font)
  (command "zoom" "e")
  (command "zoom" "0.95x")
  (princ)
)
(defun name_font ()
  (command "layer" "m" "textstyle" "c" "2" "" "")
  (setq name1 (strcat "Textstyle is \"" (getvar "textstyle") "\""))
  (setq name2 (strcat "Font is " fontnam))
  (setvar "osmode" 0)
  (command "text" "j" "bl" "0.0,0.33" "0.125" "0" name1 "" "")
  (command "text" "j" "bl" "0.0,0.125" "0.125" "0" name2 "" "")
  (setq name_style
nil
name nil
  )
  (princ)
)
Title: Re: Is there something better than vl-string-subst?
Post by: efernal on January 18, 2011, 03:44:04 PM
I use this:

(DEFUN c:char ()
  (STARTAPP (FINDFILE (STRCAT (GETENV "WINDIR") "\\SYSTEM32\\CHARMAP.EXE")))
  (PRINC)
)