Jump to content

getkword and initget help


Aditya Bagaskara

Recommended Posts

There's one function in AutoLISP that resides on 'get' functions that I don't understand. 
How exactly do you use getkword and initget? (usually they are used together)

And how do you make a command that can change option (like when you press down arrow
and you see bunch of options like arc, halfwidth etc. after inserting Polyline command) with getkword and initget?

Link to comment
Share on other sites

Yes generally initget is defined before getkword:

 

(initget "Option1 Option2")) ; note here the options are only single words, option 1 is 'option' and '1'
(setq x (getkword "Enter option (Option1 or Option2) "))

 

In the getkword you can highlight the shortcuts with square brackets and capital letters for the shortcut.:

 

(initget 1 "Yes No")
(setq x (getkword "Are you sure? [Yes/No] "))

 

Initget will limit the options you can use in getkword. Getkword is like getstring, or getreal but limited to what initget has listed. You don't need to list all the options in getkword:

 

(initget "Option1 Option2 HiddenOption")) ; note here the options are only single words, option 1 is 'option' and '1'
(setq x (getkword "Enter option (Option1 or Option2) "))

 

Generally I would use initget in the line just before getkword.

 

 

For the other art of your question I learnt alot after posting this, see Lee Macs last code:

 

Edited by Steven P
Link to comment
Share on other sites

And here is a little function example for you:

 

(defun MyTxtSelOptions ( / acount TxtLst msg MyTxt MyNum)
  (setvar "errno" 0)
  (setq acount 1)
  (setq TxtLst (list))
  (while (/= 52 (getvar "errno"))
    (initget "Opt1 Opt2 Opt3 Exit") ; Opt for alphanumeric options
    (setq msg (strcat "\nSelect Text " (rtos acount) ", or enter options: [Opt1/oPt2/opT3/Exit]: "))
    (setq MyTxt (nentsel msg) )
    (cond
      ((= 'str (type MyTxt)) ; text entered
        (setq TxtLst (append TxtLst (list MyTxt)))
        (princ MyTxt)(princ " Option Chosen")
      ) ; end cond
      ((= 'list (type MyTxt)) ; entity selected
        (setq MyTxt (car MyTxt))
        (if (wcmatch (cdr (assoc 0 (entget MyTxt)) ) "*TEXT") ; filter for entity type
          (progn
            (setq TxtLst (append TxtLst (list MyTxt)))
            (setq acount (+ acount 1))
            (princ MyTxt)
          )
          (progn ; nothing selected or escaped
            (princ "No! Text not selected")
          )
        ) ; end if
      ) ; end cond
      (t (setvar "errno" 52)
      ) ; end cond
    ) ; end conds
  ) ; end while
  TxtLst
)

 

Edited by Steven P
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...