JPlanera Posted July 12, 2012 Posted July 12, 2012 I made a couple routines for a friend who wanted to increment numbers and letters. I know there are a few different programs out there already but you only learn by trying, right! I used kind of a different approach than the programs I have seen. I tried to understand Lees suite but promptly gave up on that adventure... for now... Please take a look as I would like to know if I did anything that could be improved. All your input lately has been much appreciated, thank you all! The numbering program creates a new text style and gives the user an option to add a suffix to the number with a default option. Is the key the only way i can exit this to be able to reset my variables? (defun c:incnum(/ *error oldcmd oldtextstyle num tht inc lr bp) (setq oldcmd (getvar 'cmdecho) oldtextstyle (getvar 'textstyle) ) (defun *error* (msg) (if oldcmd (setvar 'cmdecho oldcmd)) (if oldtextstyle (setvar 'textstyle oldtextstyle)) (setq msg "Function Completed") (princ msg) (princ) ) (setvar 'cmdecho 0) (command "-style" "ROMANS" "romans.shx" "" "" "" "" "" "") (initget 7) (setq num (getint "\nEnter number to start:")) (initget 7) (setq tht (getreal "\nEnter text height desired:")) (initget 7) (setq inc (getint "\nEnter number to increment by:")) (initget "Left Right") (setq LR (getkword "\nChoose kerf [Left/Right] <Right>: ")) (if(not LR)(setq LR "Right")) (initget 1) (while (setq bp (getpoint "\nPick point--Press <Esc> when finished")) (entmake (list (cons 0 "text") (cons 1 (if (= LR "Right") (strcat(itoa num)",r") (itoa num) ) ) (cons 10 bp) (cons 11 bp) (cons 40 tht) (cons 7 "romans") ) ) (setq num (+ inc num)) (initget 1) ) ) The letter program is set up to always display capital letters regardless of the case of the input.. Also it will quit after letter "Z". (defun c:inclet(/ *error oldcmd start nascii tht bp) (setq oldcmd (getvar 'cmdecho)) (defun *error* (msg) (if oldcmd (setvar 'cmdecho oldcmd)) (setq msg "Function Completed") (princ msg) (princ) ) (setvar 'cmdecho 0) (initget "a b c d e f g h i j k l m n o p q r s t u z w x y z") (setq start (getkword "\Enter starting letter: ")) (if(> (setq nascii (ascii start)) 90) (setq nascii (- nascii 32))) (setq tht (getvar "TEXTSIZE")) (initget 1) (while(<= nascii 90) (setq bp (getpoint "\nPick point--Press <Esc> when finished")) (entmake (list (cons 0 "text") (cons 1 (chr nascii)) (cons 10 bp) (cons 11 bp) (cons 40 tht) ) ) (setq nascii (+ 1 nascii)) (initget 1) ) ) Quote
Lee Mac Posted July 12, 2012 Posted July 12, 2012 Consider the following code: ([color=BLUE]defun[/color] c:incnum ( [color=BLUE]/[/color] *error* bp inc lr num tht ) ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] msg '([color=MAROON]"Function cancelled"[/color] [color=MAROON]"quit / exit abort"[/color]))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]if[/color] ([color=BLUE]null[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"STYLE"[/color] [color=MAROON]"ROMANS"[/color])) ([color=BLUE]entmake[/color] '( (0 . [color=MAROON]"STYLE"[/color]) (100 . [color=MAROON]"AcDbSymbolTableRecord"[/color]) (100 . [color=MAROON]"AcDbTextStyleTableRecord"[/color]) (2 . [color=MAROON]"ROMANS"[/color]) (70 . 0) (40 . 0.0) (3 . [color=MAROON]"romans.shx"[/color]) ) ) ) ([color=BLUE]initget[/color] 7) ([color=BLUE]setq[/color] num ([color=BLUE]getint[/color] [color=MAROON]"\nEnter number to start: "[/color])) ([color=BLUE]initget[/color] 7) ([color=BLUE]setq[/color] tht ([color=BLUE]getreal[/color] [color=MAROON]"\nEnter text height desired: "[/color])) ([color=BLUE]initget[/color] 7) ([color=BLUE]setq[/color] inc ([color=BLUE]getint[/color] [color=MAROON]"\nEnter number to increment by: "[/color])) ([color=BLUE]initget[/color] [color=MAROON]"Left Right"[/color]) ([color=BLUE]setq[/color] lr ([color=BLUE]cond[/color] (([color=BLUE]getkword[/color] [color=MAROON]"\nChoose kerf [Left/Right] <Right>: "[/color])) ([color=MAROON]"Right"[/color]))) ([color=BLUE]while[/color] ([color=BLUE]setq[/color] bp ([color=BLUE]getpoint[/color] [color=MAROON]"\nPick point <Exit>: "[/color])) ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"TEXT"[/color]) '(7 . [color=MAROON]"ROMANS"[/color]) ([color=BLUE]cons[/color] 01 ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"Right"[/color] lr) ([color=BLUE]strcat[/color] ([color=BLUE]itoa[/color] num) [color=MAROON]",r"[/color]) ([color=BLUE]itoa[/color] num))) ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] bp 1 0)) ([color=BLUE]cons[/color] 40 tht) ) ) ([color=BLUE]setq[/color] num ([color=BLUE]+[/color] inc num)) ) ([color=BLUE]princ[/color]) ) Note that your *error* symbol is mispelled where localised. Quote
JPlanera Posted July 12, 2012 Author Posted July 12, 2012 Thanks, Lee. So using TABLSEARCH will create the style "ROMANS"? I will have to look into this TABLSEARCH further! I noticed you omitted my INITGET in the while statement... Am I correct in saying that the modified *error* routine will now accept ESC and ENTER, and because no variables have been changed, there really is now reason to restrict the user?? I will try to apply the same logic to the INCLET program to see if I can get it to work! Quote
Lee Mac Posted July 12, 2012 Posted July 12, 2012 So using TABLSEARCH will create the style "ROMANS"? No, tblsearch is merely checking the Style Table for the existence of a TextStyle with the key 'ROMANS'; if this test fails, the Style is subsequently created using entmake. I noticed you omitted my INITGET in the while statement... Am I correct in saying that the modified *error* routine will now accept ESC and ENTER No, the *error* function will only be evaluated if the user presses 'Esc', as this forces an error and ceases evaluation of the program. The if expression in the *error* function simply suppresses the error message if the user has pressed Esc to cancel the program. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.