Jump to content

can't figure this out


guitarguy1685

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...