Display "/" in getkword function as a choice?

Display "/" in getkword function as a choice?

skyline825
Explorer Explorer
1,267 Views
8 Replies
Message 1 of 9

Display "/" in getkword function as a choice?

skyline825
Explorer
Explorer

Hi all,

 

I'm writing a lisp containing a "getkword" function, which I want user to choose +,-,*,/ one of it and then let the lisp run. The routine runs just fine, however I found that the slash "/" cannot be displayed as a choice. Here is the routine of the "getkword" part:

 

(initget "+ - * /")
 (setq s_cf
  (cond
   (
    (getkword
     (strcat "\nChoose [+/-/*//] <"
      (setq s_cf
       (cond ( s_cf ) ( "+" ))
      )
      ">: "
     )
    )
   )
  ( s_cf )
 )
)

 

 

 

The (strcat "\nChoose [+/-/*//] <"  part is the problem here, as "/" functioned as a separation of the choice, I tried add quotation marks and failed, is it possible to display it as a choice perfectly?

 

Thanks

 

0 Likes
1,268 Views
8 Replies
Replies (8)
Message 2 of 9

dbroad
Mentor
Mentor

Try this: (initget "+ - * \/")

 

I don't think any workaround will display the separator character.  Unless you need the right click choice, put the choice before the [ ] characters.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 9

SeeMSixty7
Advisor
Advisor

To get your prompt to display the one "/" char use the same method as @dbroad used in his initget

 

(getkword (strcat "\nChoose [+ - * \/]"))

 

Message 4 of 9

joselggalan
Advocate
Advocate

Use (initget "local _global")

(initget "Add Subtract Multiply Divide _+ - * /")

try this example function:

;;---------------------------- GetOperator -----------------------------;;
;; José L. García G - 26/04/17                                          ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
(defun GetOperator ( / lstIget sIget tmp s_cf)
 (setq lstIget '(("+" "Add") ("-" "Subtract") ("*" "Multiply") ("/" "Divide")))
 (or *op* (setq *op* "Add"))
 (setq s_cf (cadr (assoc *op* (mapcar 'reverse lstIget))))
 
 ;;"Add/Subtract/Multiply/Divide"
 (setq sIget (apply 'strcat (mapcar '(lambda (x) (strcat (cadr x) "/")) lstIget))
       sIget (vl-string-right-trim "/" sIget)
       sIget (vl-string-subst (strcat "<" *op* ">") *op* sIget))
 
 ;;use (initget "local _global")
 ;;(initget "Add Subtract Multiply Divide _+ - * /")
 (initget
  (strcat (apply 'strcat (mapcar '(lambda (x) (strcat (cadr x) " ")) lstIget))
	  "_"
	  (apply 'strcat (mapcar '(lambda (x) (strcat (car x) " ")) lstIget))))
 (if (setq tmp (getkword (strcat "\nChoose [" sIget "]: ")))
  (setq s_cf tmp
	*op* (cadr (assoc s_cf lstIget)))
 )
 s_cf 
)

test:

(apply (read (GetOperator)) (list 2 3.))

 

 

 

Message 5 of 9

skyline825
Explorer
Explorer

Thanks everyone.

Still the slash char cannot display on the command line using the above method, seems it doesn't have a normal way to simply display it, now I changed my routine with no user input required. Thanks.

0 Likes
Message 6 of 9

scot-65
Advisor
Advisor
Another item you might want to consider is
the Dynprompt behavior. The forward slash
starts a new line (and is therefore reserved).
On the command line, a space replaces the
character.

Command: (ascii "/")
47

Command: (chr 47)
"/"

Or try `/
(reverse quote next to the "1" on the keyboard)

We work in Architectural units and fractions never
displayed properly since the dynprompt came into play.
I have not tried it lately though.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 9

SeeMSixty7
Advisor
Advisor

I have always been a command line person and simply use the command line and turn off Dynamic Command input. The following code works fine. in the AutoCAD Command Text window [F2]

 

Command: (progn
(_> (initget "+ - * /")
(_> (setq test (getkword "[+ - * /]"))
(_> )
[+ - * /]/
"/"

 

But it fails miserably in the Command line area and the Dynamic Input areas. Just annoying! Thanks @scot-65 I would not have thought to consider dynamic prompt. DOH!

 

You can cheat and use this to bump the prompt up one notch on the command window where it will display correctly.

 

Command: (progn
(_> (initget "+ - * \/")
(_> (princ "\nOptions [+ - * /]")
(_> (setq test (getkword "\nEnter Option:"))
(_> )
Options [+ - * /]
Enter Option:/
"/"

 

Good luck,

0 Likes
Message 8 of 9

scot-65
Advisor
Advisor

OK, outside the box time...

 

testKWORD.jpg

 

Scot-65


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 9 of 9

roland.r71
Collaborator
Collaborator

@skyline825 wrote:

Thanks everyone.

Still the slash char cannot display on the command line using the above method, seems it doesn't have a normal way to simply display it, now I changed my routine with no user input required. Thanks.



Its a funny one to play with, but ultimately avoiding the character is the only solution.

 

Got it to display nicely at the crosshair, with the choices visible in a column, which you can 'scroll' with arrow keys. (with a dot in front of active choice.

But as you said, you just can't get it to show up on the commandline prompt.

 

While trying all sorts of stuff i noticed a few things: the Getkword requires the / as a separator, otherwise the choices don't display properly.

Adding a \ only seems to work. For as long as the / is the last choice. Put an extra choice behind it and it goes sideways...

 

like: "\nChoose [+/-/*\/] <"

● +

   -

   *

   /

 

looks okay, but add 9 to the choices and you get: "\nChoose [+/-/*\//9] <"

● +

   -

   *

   /9

 

 

As the / separator is visible it looks awkward on screen too: Choose [+/-/*//] <+>: will not make the / look like a choice, to anyone but you.

 

...and nothing seems to get it visible on the commandline.

 

When a character is used by the system, there is only one way to go about it: Avoid!

So you made the right choice 😉

0 Likes