Make GetKword Persistant for major program options

Make GetKword Persistant for major program options

T2ioTD
Enthusiast Enthusiast
997 Views
5 Replies
Message 1 of 6

Make GetKword Persistant for major program options

T2ioTD
Enthusiast
Enthusiast

Dear All

 

Say I want to run a simple program that just offers 3 options always on the bottom of the screen (command line) that are : Red, Blue, Exit.

and the user can keep on clicking points and the programs responds with "Red" alert if the Red option was the last one pressed, and and alert "Blue" if the Blue option was the last one pressed, and the program will exit if the Keyword Exit is pressed.

 

Obviously the Init and GetKword have to be included inside a While, but i am having difficulty writing the proper structure.

 

Can you help please?

0 Likes
Accepted solutions (1)
998 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

 

I'm not sure to completely understand but I try something:

 

(defun c:foo (/ kw pt)
  (initget 1 "Red Blue Exit")
  (if
    (/=	(setq kw (getkword "\nChoose an option [Red/Blue/Exit]: "))
	"Exit"
    )
     (while
       (progn
	 (initget 1 "Red Blue Exit")
	 (/= (setq pt (getpoint "\nPick a point or [Red/Blue/Exit]: "))
	     "Exit"
	 )
       )
	(if (listp pt)
	  (alert kw)
	  (setq kw pt)
	)
     )
  )
  (princ)
)

 

Or, if you want "Exit" to be the dfault value (i.e. hit enter to exit).

 

(defun c:bar (/ kw pt)
  (initget "Red Blue Exit")
  (if
    (and
      (setq kw (getkword "\nChoose an option [Red/Blue/Exit] <Exit>: "))
      (/= kw "Exit")
    )
     (while
       (progn
	 (initget "Red Blue Exit")
	 (and
	   (setq
	     pt	(getpoint "\nPick a point or [Red/Blue/Exit] <Exit>: ")
	   )
	   (/= pt "Exit")
	 )
       )
	(if (listp pt)
	  (alert kw)
	  (setq kw pt)
	)
     )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

T2ioTD
Enthusiast
Enthusiast

The behavior is exactly what I need.

Yet, I wanted Red and Blue to represent 2 different routines, say a circle and a point, (or if 2 points, than at least i wanted the getpoint routine to be written in two different blocs of codes, so that I can replace these dummy functions with some polyline blocs of code I am writing.

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@T2ioTD wrote:

.... 

Say I want to run a simple program that just offers 3 options always on the bottom of the screen (command line) that are : Red, Blue, Exit.

and the user can keep on clicking points and the programs responds with "Red" alert if the Red option was the last one pressed, and and alert "Blue" if the Blue option was the last one pressed, and the program will exit if the Keyword Exit is pressed.

....


It is also possible to actually do what you asked for [by content within the prompt, not through an actual (alert) function], that is, for it to prompt you with the specific option that's "current" [the last one used] and offer the others [including exiting] as options.  So if Red was the last one, the prompt could be:

 

"Pick point for doing the Red thing or [Blue/eXit]: "

 

And once you choose the Blue option, the prompt would change to:

 

"Pick point for doing the Blue thing or [Red/eXit]: "

 

For an example of how to do that kind of thing, see ConstLines.lsp, here.  It's slightly different, in offering <exit> as the default, on pressing Enter/space, rather than typing something for it as an option, but it can be adjusted to do it in the latter way if preferred.

Kent Cooper, AIA
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

... see ConstLines.lsp, here.  It's slightly different, in offering <exit> as the default, on pressing Enter/space, rather than typing something for it as an option....


In other words, the prompts for your situation could be something like:

 

"Pick point for doing the Red thing, or [Blue] <exit>: "

 

and when you've switched to the Blue option:

 

"Pick point for doing the Blue thing, or [Red] <exit>: "

 

which seems preferable to me, compared to having to type in an E or X or whatever to get exit as an explicitly-specified option.  Does that sound useful for your situation?

Kent Cooper, AIA
0 Likes
Message 6 of 6

T2ioTD
Enthusiast
Enthusiast

Kent1Cooper: yes I tried your program and it is indeed superior to my needs as the options shown are dynamically complementing the current user choice. However it is also more complicated to dissect, thus I will file it and save it for future use, once my lisp skills increase.

 

Many thanks.

0 Likes