- ;;code made by Jef!;;2014-02-08(defun c:WID ( / *error* startingweldinput singleletterlist doubleletterlist weldascii counter txtpt leaderpt weldID) (defun *error* (msg) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " msg)) ) (princ) ) (initget "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA BB CC DD EE FF GG HH II JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ") (setq startingweldinput (getkword "\nEnter weld identification letter or enter to exit: ")) (setq singleletterlist (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z") doubleletterlist (list "AA" "BB" "CC" "DD" "EE" "FF" "GG" "HH" "II" "JJ" "KK" "LL" "MM" "NN" "OO" "PP" "QQ" "RR" "SS" "TT" "UU" "VV" "WW" "XX" "YY" "ZZ") weldascii (ascii startingweldinput) counter (+ 1 (- weldascii 65))) (cond ( (member startingweldinput singleletterlist) (while (and [b][color=darkorange](not (if (> counter 52)(progn(princ "\n\nout of letters, aborting\n")[u] t [/u])))[/color][/b] [color=green](setq txtpt (getpoint "\nChoose a point for text or enter to exit: ")) (setq leaderpt (getpoint "\nChoose a point for leader or enter to exit: "))[/color] (princ) ) (if ( counter 26)(progn(princ "\n\nout of letters, aborting\n")t)))[/color] [color=blue](setq txtpt (getpoint "\nChoose a point for text or enter to exit: ")) (setq leaderpt (getpoint "\nChoose a point for leader or enter to exit: "))[/color] (princ) ) (setq weldID (strcat (chr weldascii)(chr weldascii))) (command "mleader" txtpt txtpt weldID leaderpt) (setq weldascii (+ 1 weldascii)) (setq counter (+ 1 counter)) (princ) ) ) ))
Path I took:
I check the input and retrieve the ascii. if double letter it gets ascii of first char.
I start a counter (setq counter (+ 1 (- weldascii 65))). Basically the counter get value 1 for A, 2 for B and so on. I use it to excape the while prevent getting over z (or zz).
I then check if the original input is part of single or double char list, then proceed with conditional based upon that. The ascii number is used for the WeldID.
When its single input i also use the ascii number and if ascii go over 90 (z) I remove 26 from its value (to start back at A) and use it twice (AA) .
I so never figured that one out, gurus..
its drove me crazy for hours!!! need a guru to explain...
At the beginning, the orange lines had (exit) instead of t... like this
(not (if (> counter 52)(progn(princ "\n\nout of letters, aborting\n") (exit))))
I cant figure out why, when the counter got to 52, the progn seemed to be evaluated. The (princ "\nOut of letters, routine is interrupted") was processed, but not the (exit). Cad/vlide frooze and I got $1 on console. I tried to monitor variables, but since Cad needed user input I never figured out the way to proceed. Why only half the progn was processed and not the exit?
I ended up simply returning true (t), with the "not" before the the routine get interrupted by the and of the while.. so instead of the f stopping it, its the while/and who make all the calcelling. make sense? =D
@ksperopoulos. Fully working. I hope you'll enjoy =)
Cheers
Jef!
ps.: all comments are welcome