guitarguy1685 发表于 2022-7-6 11:54:57

can't figure this out

I have this code
 

(setq FPname (cond ((getstring (strcat "\nF-Part to insert : ")))            (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 : ")))         (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?

Lee Mac 发表于 2022-7-6 12:09:02

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).

Lee Mac 发表于 2022-7-6 12:20:38

Something like would suffice:
 

(or *def* (setq *def* "Default"))(or (eq "" (setq tmp (getstring t (strcat "\nString: "))))   (setq *def* tmp))Or
 

(or *def* (setq *def* "Default"))(setq *def* (cond ((= "" (setq tmp (getstring (strcat "\nString: ")))) *def*)               (tmp)))

David Bethel 发表于 2022-7-6 12:34:31

Maybe a little old fashion but I still prefer a more straight forward approach.
 

(setq def_input "Default") (while (or (not input)            (not (snvalid input)))      (setq input (getstring (strcat "\nString Input :   ")))      (cond ((= input "")(setq input def_input))))
 
 
This gives you unlimited( or ) and ( cond ) testing and is a bit more readable to me.My $0.02.-David

guitarguy1685 发表于 2022-7-6 12:44:05

 
wow that makes total sense.thanks so much

guitarguy1685 发表于 2022-7-6 12:48:50

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*.

Lee Mac 发表于 2022-7-6 13:02:34

 
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.
页: [1]
查看完整版本: can't figure this out