Command line button

Command line button

davidlanesmith673
Enthusiast Enthusiast
911 Views
7 Replies
Message 1 of 8

Command line button

davidlanesmith673
Enthusiast
Enthusiast

I was wondering if there is a way to add buttons to your own commands that show up in the command line, like in PEDIT where there is the OPEN, JOIN, WIDTH... options that you can click:

davidlanesmith673_0-1628691243623.png

 

0 Likes
Accepted solutions (3)
912 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Sure, like this...

 

 

(defun c:TestYourPedit ()

  (initget "Open Join Width")
  (getkword "PEDIT Enter an option [Open/Join/Width]: ")
  )

 

 

 
0 Likes
Message 3 of 8

davidlanesmith673
Enthusiast
Enthusiast

Thanks, exactly what I need!!

0 Likes
Message 4 of 8

Anonymous
Not applicable

You can also specify a default selection, like this:

(getkword "PEDIT Enter an option [Open/Join/Width]<Join>: ")
0 Likes
Message 5 of 8

davidlanesmith673
Enthusiast
Enthusiast

I tried that, and I seems to be more complicated than just adding <Join> at the end.

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor
Accepted solution

@davidlanesmith673 wrote:

I tried that, and I seems to be more complicated than just adding <Join> at the end.


(defun c:TestYourPedit ()

(initget "Open Join Width");<-- this allows the user to press enter without entering a keyword
(Setq opt (getkword "PEDIT Enter an option [Open/Join/Width]<Join>: "))
(setq opt (if (null opt) "Join" opt));<-- if user pressed enter, Join will be the default
)

 

Command: TESTYOURPEDIT
PEDIT Enter an option [Open/Join/Width]<Join>: user pressed enter
"Join"


Command: TESTYOURPEDIT
PEDIT Enter an option [Open/Join/Width]<Join> : w
"Width"

 

If you include 1 on the initget line  (initget 1 "Open Join Width") The user is force to select among the choice


Command: TESTYOURPEDIT

PEDIT Enter an option [Open/Join/Width]: user pressed enter

Invalid option keyword.

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

You can also, if you like, have it offer your prior choice as default on subsequent use, so you can use Enter/space to accept that, instead of typing/picking it again, similar to the way many AutoCAD commands work.  And you can have an initial default to offer, or not.  This is a way if you want an initial default offered on first use:

 

(defun c:TestYourPedit ()

  (initget "Open Join Width")
  (setq opt ; must be a global [not localized] variable to remain available on subsequent use

    (cond

      ( (getkword ; <-- returns nil on Enter

          (strcat

            "PEDIT Enter an option [Open/Join/Width] <"

            (cond (opt) ("Join")); <-- prior choice as default if present, otherwise Join

            ">: "

          ); strcat

        ); getkword

      ); end User-input condition

      (opt); <-- prior choice on Enter, if present

      ("Join"); <-- initial default on Enter at first use

    ); cond

  ); setq

  .... whatever ....
); defun

 

This is a way if you don't want an initial default offered, but want to require the User to specify the first time:

 

(defun c:TestYourPedit ()

  (initget (if opt 0 1) "Open Join Width"); <-- allows Enter only if there's a prior choice
  (setq opt

    (cond

      ( (getkword ; <-- returns nil on Enter [only when permitted]

          (strcat

            "PEDIT Enter an option [Open/Join/Width]"

            (if opt (strcat " <" opt ">") ""); <-- offers prior choice default only if present

            ": "

          ); strcat

        ); getkword

      ); end User-input condition

      (opt); <-- prior choice on Enter when permitted

    ); cond
  ); setq

  .... whatever ....

); defun

Kent Cooper, AIA
0 Likes
Message 8 of 8

davidlanesmith673
Enthusiast
Enthusiast
Ok, yah that makes sense. Before I had included 1 on the initget line.
0 Likes