guitarguy1685 Posted January 7, 2010 Share Posted January 7, 2010 I have this code (setq FPname (cond ((getstring (strcat "\nF-Part to insert <" FPname ">: "))) (FPname))) In this code FPname is a global variable. This way it is remembered the next time I use this lisp. so it would work like this 1st time run "f-Part to insert >: " i might enter 1234 2nd time run "f-part to insert : " I just press enter Right now if I press enter FPname goes to nill. This worked for me before in this lisp (setq ANG_L2 (cond ((getdist (strcat "\nSpecify size of second leg <" (rtos ANG_L2) ">: "))) (ANG_L2))) but it is just slightly different. In this one i was using integers and in the first one i'm using a string. any thoughts? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 7, 2010 Share Posted January 7, 2010 You won't be able to use the same construct with getstring. Whereas getint, getreal etc return nil on null input, getstring will return an empty string (i.e. non-nil). Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 7, 2010 Share Posted January 7, 2010 Something like would suffice: (or *def* (setq *def* "Default")) (or (eq "" (setq tmp (getstring t (strcat "\nString <" *def* "> : ")))) (setq *def* tmp)) Or (or *def* (setq *def* "Default")) (setq *def* (cond ((= "" (setq tmp (getstring (strcat "\nString <" *def* "> : ")))) *def*) (tmp))) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 7, 2010 Share Posted January 7, 2010 Maybe a little old fashion but I still prefer a more straight forward approach. [b][color=BLACK]([/color][/b]setq def_input [color=#2f4f4f]"Default"[/color][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]or [b][color=NAVY]([/color][/b]not input[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]snvalid input[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq input [b][color=NAVY]([/color][/b]getstring [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nString Input <"[/color] def_input [color=#2f4f4f]">: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]cond [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]= input [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq input def_input[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] This gives you unlimited ( or ) and ( cond ) testing and is a bit more readable to me. My $0.02. -David Quote Link to comment Share on other sites More sharing options...
guitarguy1685 Posted January 7, 2010 Author Share Posted January 7, 2010 You won't be able to use the same construct with getstring. Whereas getint, getreal etc return nil on null input, getstring will return an empty string (i.e. non-nil). wow that makes total sense. thanks so much Quote Link to comment Share on other sites More sharing options...
guitarguy1685 Posted January 8, 2010 Author Share Posted January 8, 2010 very interesting. so many ways to get the same result. I do appreciate your guys help. Is there a place to submit lisps on this site? i'd like to submit what I've done with this sites help. Maybe it can help others. btw is there any purpose to using the asterisks around *def* ? I noticed it with some code I got from an error handler where they used *error*. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 8, 2010 Share Posted January 8, 2010 very interesting. so many ways to get the same result. I do appreciate your guys help. Is there a place to submit lisps on this site? i'd like to submit what I've done with this sites help. Maybe it can help others. btw is there any purpose to using the asterisks around *def* ? I noticed it with some code I got from an error handler where they used *error*. I use asterisks in Global variables just to make them "less common" to avoid clashes with other programs. In essence, a global variable could be named in the same fashion as a local one, but if two programs use the same global variable, there could be undesired consequences. *error* is something completely different, it is AutoCAD's user-definable error handling function. Quote Link to comment Share on other sites More sharing options...
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.