Is it possible for the lisp name itself to contain an option string?

Is it possible for the lisp name itself to contain an option string?

Anonymous
Not applicable
801 Views
6 Replies
Message 1 of 7

Is it possible for the lisp name itself to contain an option string?

Anonymous
Not applicable

Hey Guys,

 

Quick question, is there a way for CAD to accept skipping a sub-option in a lisp if you provide the info up front? Essentially (per the example below)  if I wanted to say "hello world" I could just type "greeting" and then "w". However if I'm familiar with the lisp and know the options already is there a way to type something like "greeting\w" in the command line and have it skip straight to the alert end result for the sub option? Obviously if this worked somehow I would like to continue the tree for more complicated lisps, example being "greeting\w\g\j" if said sub options existed.

(defun c:greeting ( / n1 )
	(initget 1 "w f")
	(setq n1 (getkword "GREET WHO?: [(W)orld/(F)riends] > "))
	(cond
		(
			(eq n1 "w")
			(alert "hello world!")
		)
		(
			(eq n1 "f")
			(alert "hello friends!")
		)
	)
	(princ)
)

 

0 Likes
Accepted solutions (2)
802 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

You would do that as a function with arguments, rather than as a command.  For example:

 

(defun greeting (who / greetlist whom)
  (setq greetlist '(("w" "world") ("f" "friends")))
  (alert
    (if (setq whom (last (assoc (strcase who T) greetlist)))
      (strcat "hello " whom "!"); then
      "Not a valid greeting recipient option." ; else
    ); if
  ); alert
  (princ)
)

 

Usage:

  (greeting "W")  [note that it's set up to accept either upper- or lower-case initial letters]

  (greeting "f")

But:

  (greeting "x")

will get you the scolding.

 

Such a thing can be built to take any number of arguments:

(defun greeting (who what where when how why / local variables) ....

Kent Cooper, AIA
0 Likes
Message 3 of 7

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

Hey Guys,

 

Quick question, is there a way for CAD to accept skipping a sub-option in a lisp if you provide the info up front? Essentially (per the example below)  if I wanted to say "hello world" I could just type "greeting" and then "w". However if I'm familiar with the lisp and know the options already is there a way to type something like "greeting\w" in the command line and have it skip straight to the alert end result for the sub option? Obviously if this worked somehow I would like to continue the tree for more complicated lisps, example being "greeting\w\g\j" if said sub options existed.

 


Not necessarily like what you had but instead of using "greeting\w" we can use "greeting:w"

 

(Defun c:greeting:W ()
  (greeting "W")
  )
(Defun c:greeting:f ()
  (greeting "F")
  )
(Defun c:greeting ()
  (greeting nil)
  )

(defun greeting ( op / n1 )
	(initget 1 "W F")
  	(cond
	  ((eq op "W") (alert "hello world!"))
	  ((eq op "F") (alert "hello friends!"))
	  ((setq n1 (getkword "GREET WHO?: [World/Friends] > "))
	   	(eval (cadr (assoc n1
				   '(("W" (c:greeting:W))
				     ("F" (c:greeting:F))
				     )
				   )
			    )
		      )
	   )
      )
  )

 

HTH

 

Quick survey: 

Does this ever happen to you? Alert does not show the pop-up thingy but value appears only on  the command prompt?

This happen to me in AutoCAD 2017,  i think i broke it 😀. Or is this siilar to the 2Dpoly type that i'm not even aware of.

Only shows there are still a lot in AutoCAD that i dont know.

 

0 Likes
Message 4 of 7

ronjonp
Mentor
Mentor

You can use a global variable like so to remember your last input:

(defun c:greeting nil
  (or *n1* (setq *n1* "World"))
  (initget 1 "World Friends")
  (setq	*n1* (cond ((getkword (strcat "GREET WHO?: [World/Friends]<" *n1* "> ")))
		   (*n1*)
	     )
  )
  (alert (strcat "Hello " *n1* "!"))
  (princ)
)
0 Likes
Message 5 of 7

ronjonp
Mentor
Mentor

@pbejse wrote:

Quick survey: 

Does this ever happen to you? Alert does not show the pop-up thingy but value appears only on  the command prompt?

This happen to me in AutoCAD 2017,  i think i broke it 😀. Or is this siilar to the 2Dpoly type that i'm not even aware of.

Only shows there are still a lot in AutoCAD that i dont know.

 


@pbejse  Look into the DYNMODE and DYNPROMPT variables.

0 Likes
Message 6 of 7

Anonymous
Not applicable

Thanks all for the input, massive help!

0 Likes
Message 7 of 7

pbejse
Mentor
Mentor

@ronjonp wrote:

@pbejse  Look into the DYNMODE and DYNPROMPT variables.


 

Tried both and every combination and still no joy, I'll keep looking and let you guys know.

 

No Joy.png

 

 

0 Likes