Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getkword help

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
882 Views, 6 Replies

Getkword help

Hi guys-

So I have a lisp routine I'm making and I having problems with the getkword/initget function. I want my users to be able to just click Enter to select the default option. I haven't set a bit to leave the option open and I used [ ] < > to set the default value and when I hit enter I get null as my result. Dose anyone know what I'm doing wrong? Please help.

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

The return will be nil if the user just hits enter.  You must program for the occasion following a similar syntax to that given below.

 

(setq tempAgl (getint "\Specify rotation angle increments. <5>: "))
  (if (= tempAgl nil)
    (setq tempAgl 5)
    )

Message 3 of 7
Anonymous
in reply to: Anonymous

Ah.... I'll give this a try. Thanks.
Message 4 of 7
Anonymous
in reply to: Anonymous

Thanks. That was it. I thought it would be some thing simple. 🙂
Message 5 of 7
Kent1Cooper
in reply to: Anonymous

You can extend that for enhanced operation, for example to save any prior value entered and offer that as the default on subsequent use, rather than always offering the same default.  There are a couple of ways to do that, in this case with integer values as in the other reply, if you want an initial default of 5:

 

(setq IntVal

  (cond

    ( (getint ; returns nil on Enter

        (strcat

          "\nEnter integer value: <"

          (if IntVal (itoa IntVal) "5"); offer default [prior value if any]

          ">: "

        ); strcat

      ); getint

    ); end User-types-integer condition

    (IntVal); User hit Enter, and there's a prior value [returns nil if not]

    (5); User hit Enter without a prior value [use initial default]

  ); cond

); setq

 

Or set the initial default first:

 

(if (not IntVal) (setq IntVal 5))

(setq IntVal

  (cond

    ((getint (strcat "\nEnter integer value: <" (itoa IntVal) ">: "))); nil on Enter

    (IntVal); User hit Enter [keep current value, whether initial default or prior User value]

  ); cond

); setq

 

Neither of those uses (initget)/(getkword), but you might have a use for (initget) in that situation, for example to prevent the User from typing 0 or a negative number.  The (getkword) function is more often of value when there are multiple options to choose from rather than a single default value to accept or not, and/or when the value is a text string, for example a Layer name.  You'll find a lot of examples in this Forum -- just put (getkword) in the Search window.

Kent Cooper, AIA
Message 6 of 7
Anonymous
in reply to: Kent1Cooper

this is cool and useful.... but I'm using names of blocks. not integers. Thanks though.
Message 7 of 7
Anonymous
in reply to: Anonymous

So I just figured out that I can apply this technique to the getkword function, and it solved a huge problem I was having. again thanks. 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report