atb1984 Posted August 17, 2010 Posted August 17, 2010 I'm trying to get a better grasp on vlisp. I use a lot of simple routines because I prefer to type commands rather than click around the ribbon and the rest of the screen. I started a lisp routine to clean up plan drawings using the 'setbylayer' command. I added to it so that the user also has the option to set the ltscale of objects. I'm trying to give the user the option to answer Y or N to a prompt. The routine works, but the response is case sensitive, so "y" is ok, but "Y" is invalid. How can I adjust this routine so that the input is not case sensitive. beck.LSP Is this total trash so far? Do I need to completely start over? It's starting to be a lot of 'if' conditions. Thanks for looking. Autocad MEP 2010 (at work) and Autocad 2011 (@ home) Quote
Lee Mac Posted August 17, 2010 Posted August 17, 2010 Haven't properly looked at the code, but look into the combination of initget and getkword - make sure you read the whole Developer help file around these functions Quote
atb1984 Posted August 17, 2010 Author Posted August 17, 2010 Sorry about the attachment, I should have read the sticky post first... here's the code for my routine: ;;;------------------------------------------------------------------------------------------------------------------------------------------------------- ;;; Function "SBL" changes the properties of all objects in the model space to "By Layer", and also gives the option to change the objects ltscale. (defun c:SBL (/ tmode yes_no scale) (setvar "cmdecho" 0) ; turns off prompt echo (setq tmode (getvar "tilemode")) ; assign tilemode varialble to 'tmode' (if (= tmode 0) (alert "You are currently in paper space.\nSwitch to model space first.") ; if paper space is active, alert user and terminate command (progn ; if model space is active, continue command (command "_.setbylayer" "all" "" "y" "y") ; executes the "setbylayer" command (terpri) ; prints a blank line (setq yes_no (getstring "Do you also want to change the Linetype Scale of all objects? Y or N? ")) ; prompts user to change ltscale (if (= yes_no "y") ; if user enters y, do the following: (progn (setq scale (getreal "\nEnter new ltscale... ")) ; prompt user for new ltscale value (terpri) ; prints a blank line (command "chprop" "all" "" "ltscale" scale "") ; changes ltscale to user-specified value (princ "\nLinetype scale of objects successfully changed. ")) ; confirms change of ltscale (if (= yes_no "n") ; if user enters n, do the following (princ "\nLinetype scale will not change. ") ; confirm ltscale will not change (alert "Invalid entry.\nEnter 'Y' or 'N'"))))) ; alert user they did not enter either "y" or "n". (princ)) ; exit quietly ;;;------------------------------------------------------------------------------------------------------------------------------------------------------- Quote
atb1984 Posted August 17, 2010 Author Posted August 17, 2010 Ok, I'll check those out tonight, thanks. I seriously need to quit working on this while I'm at work anyways! I keep thinking of ways I should improve this and i get caught up... I'm using my old AutoCAD 2004 Bible as reference but it covers Vlisp very briefly. Quote
Lee Mac Posted August 17, 2010 Posted August 17, 2010 Your best reference for functions is the VLIDE Help file - the help for the vla-* functions is written for VBA, but you can easily make the connection to VLISP after some practice. Lee Quote
David Bethel Posted August 17, 2010 Posted August 17, 2010 here's a basic primer on Yes No [color=#8b4513];;;Forces A U Input - NO DEFAULT[/color] [b][color=BLACK]([/color][/b]initget 1 [color=#2f4f4f]"Yes No"[/color][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]setq input [b][color=FUCHSIA]([/color][/b]getkword [color=#2f4f4f]"\nInput - Yes/No: "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];;;Default To Yes - Even With Empty Input[/color] [b][color=BLACK]([/color][/b]initget [color=#2f4f4f]"Yes No"[/color][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]setq input [b][color=FUCHSIA]([/color][/b]getkword [color=#2f4f4f]"\nInput - Yes/No <Y>: "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]if [b][color=FUCHSIA]([/color][/b]/= input [color=#2f4f4f]"No"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq input [color=#2f4f4f]"Yes"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];;;Multiple Choice - Default To Dontknow[/color] [b][color=BLACK]([/color][/b]initget [color=#2f4f4f]"Yes No Dontknow"[/color][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]setq input [b][color=FUCHSIA]([/color][/b]getkword [color=#2f4f4f]"\nInput - Yes/No/Dontknow <D>: "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]cond [b][color=FUCHSIA]([/color][/b][b][color=NAVY]([/color][/b]= input [color=#2f4f4f]"Yes"[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]do_this[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b][b][color=NAVY]([/color][/b]= input [color=#2f4f4f]"No"[/color][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]do_that[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]T [b][color=NAVY]([/color][/b]donot_do_it[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] HTH -David Quote
atb1984 Posted August 17, 2010 Author Posted August 17, 2010 I looked up 'initget' and 'getkword' in the help file. They were exactly what I needed. I didn't want to 'defualt to Yes', and looking at your code, David, I don't completely understand the 'Dontknow' scenario... -I don't know Dontknow . (initget 1 "Yes No") seems best for this application. Thanks so much for your help guys. Quote
Lee Mac Posted August 18, 2010 Posted August 18, 2010 Some more examples for you to look over: [i][color=#990099];; Initget / GetK(ey)word Examples[/color][/i] [i][color=#990099];; © Lee Mac 2010[/color][/i] [i][color=#990099];-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[/color][/i] [i][color=#990099];; Note 1: On Prompt String Format[/color][/i] [i][color=#990099];; In all examples, to achieve correct display[/color][/i] [i][color=#990099];; when DYNamic Input (DYNMODE=1) is enabled,[/color][/i] [i][color=#990099];; prompt string must be formatted thus:[/color][/i] [i][color=#990099];; [Option1/Option2/Option3][/color][/i] [i][color=#990099];; Or, with default:[/color][/i] [i][color=#990099];; [Option1/Option2/Option3] <Option1>[/color][/i] [i][color=#990099];-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[/color][/i] [i][color=#990099];; Note 2: On Global Variable Format[/color][/i] [i][color=#990099];; In all examples utilising global variables[/color][/i] [i][color=#990099];; asterisks are included in variable names to decrease[/color][/i] [i][color=#990099];; risk of variable names clashing with unlocalised variables[/color][/i] [i][color=#990099];; from other programs. Asterisks are used for no other purpose.[/color][/i] [i][color=#990099];-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[/color][/i] [i][color=#990099];; 1. Force User Input (initget bit 1)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ans [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma]: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; User must select a choice to continue, else[/color][/i] [i][color=#990099];; Esc must be used to cancel evaluation[/color][/i] [i][color=#990099];-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[/color][/i] [i][color=#990099];; 2. Preset Default (Alpha)[/color][/i] [i][color=#990099];; a)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ans [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma] <Alpha>: "[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=#a52a2a]"Alpha"[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; b)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ans [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma] <Alpha>: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] ans[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ans [b][color=#a52a2a]"Alpha"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[/color][/i] [i][color=#990099];; 3. Dynamic Default (utlisation of Global Variable: *ans*)[/color][/i] [i][color=#990099];; a)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]or[/color][/b] *ans* [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=#a52a2a]"Alpha"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma] <"[/color][/b] *ans* [b][color=#a52a2a]">: "[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] *ans* [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099];; b)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] *ans*[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=#a52a2a]"Alpha"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma] <"[/color][/b] *ans* [b][color=#a52a2a]">: "[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] *ans* [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [i][color=#990099];; c)[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]initget[/color][/b] [b][color=#a52a2a]"Alpha Beta Gamma"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getkword[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#a52a2a]"\nChoose [Alpha/Beta/Gamma] <"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] *ans* [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] *ans* [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=#a52a2a]"Alpha"[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=#a52a2a]">: "[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] *ans* [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote
alanjt Posted August 18, 2010 Posted August 18, 2010 Don't forget, the keyword trigger is based on the capitalized letter. eg. (initget 0 "Cat Dog dinoSaur") (getkword "\nChoose an animal [Cat/Dog/dinoSaur]: ") 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.