AutoLisp Chapter - 4

AutoLisp Chapter - 4
Site menu


Login form


Search


Site friends
  • Create your own site


  • Statistics

    Total online: 1
    Guests: 1
    Users: 0


    Welcome, Guest · RSS 16 September 2024
    AutoLisp Tutorial for Intermediate
     

    Chapter - 4
     
     
    Topics Coverd In this Chapter
    • Numeric Text Input : Getreal & Getint
    • String Text Input : Getstring & Getkword
    • Use of Initget & Getkword 


    Numeric Text Input : Getreal & Getint
     
    When you want to ask user for some numeric value you may use GetReal or Getint. the basic difference between this two function is Getreal is used for Real Values (e.g. 2.54 , 100.152 etc.) and Getint is used for integer value. both functions re used a same way.
     
    The syntax for Getreal is
     
    (getreal [msg])
     
    And for Getint is
     
    (getint [msg])
     
    msg

    A string to be displayed to prompt the user.

    Values passed to getint can range from -32,768 to +32,767. If the user enters something other than an integer, getint displays the message, “Requires an integer value,” and allows the user to try again. also you can use some additional control by using Initget. with Initget, you can force a Get function not to accept zero or negative values. Unlike most functions, Initget always returns nil.
     
    Example
     
    (setq tx1 (getreal "Enter real Number :"))
     
    (setq tx2 (getint "Enter Integer :"))

    String Text Input : Getstring & Getkword
     
    Getstring is used for asking String.
     
    The syntax for Getstring is
     
    (getstring [cr] [msg])
     

    Arguments

    cr

    If supplied and not nil, this argument indicates that users can include blanks in their input string (and must terminate the string by pressing ENTER). Otherwise, the input string is terminated by entering a space or pressing ENTER.

    msg

    A string to be displayed to prompt the user.
     
    Example
     
    (setq str1 (getstring "Enter your country Name :"))
     
    The following prompth will appear
     
    Enter your country Name :
     
    Enter India and check value of variable str1 by entering !str1
     
    now try this
     
    (setq str1 (getstring "Enter your Full Name :"))
     
    try entering your first and last name. as your type your first name and press space bar the getstring function ends and you no more entering your last name. to allow space in string you must use T in getstring function. to do so look below
     
    (setq str1 (getstring T "Enter your country Name :"))
     
    now try to entering your first Name and last name with space. you could do this. check the value of variable str1 by entering !str1 at command line.
    Use of Initget
     
    The syntax for Initget is
     
    (initget [bits] [string])
     
    you can use Initget with functions like getint, getreal, getdist, getangle, getorient, getpoint, getcorner, getkword, entsel, nentsel, and nentselp.
      

    bits

    A bit-coded integer that allows or disallows certain types of user input. The bits can be added together in any combination to form a value between 0 and 255. If no bits argument is supplied, zero (no conditions) is assumed. The bit values are as follows:

    1(bit 0) Prevents the user by entering only ENTER, Null input not allowed.

    2(bit 1) Prevents the user entering zero.

    4(bit 2) Prevents the user by entering a negative value.

    8(bit 3) Allows the user to enter a point outside the current drawing limits. This condition applies to the next user-input function even if the AutoCAD system variable LIMCHECK is currently set.

    16(bit 4) Return 3D point.
      
    32(bit 5) Uses dashed lines when drawing a rubber-band line or box. For those functions with which the user can specify a point by selecting a location in the drawing area, this bit value causes the rubber-band line or box to be dashed instead of solid. (Some display drivers use a distinctive color instead of dashed lines.) If the system variable POPUPS is 0, AutoCAD ignores this bit.

    64(bit 6) Prohibits input of a Z coordinate to the getdist function; lets an application ensure that this function returns a 2D distance.

    128(bit 7) Allows arbitrary input as if it is a keyword, first honoring any other control bits and listed keywords. This bit takes precedence over bit 0; if bits 7 and 0 are set and the user presses ENTER, a null string is returned.

    256(bit 8) Give direct distance input precedence over arbitrary input. For external applications, arbitrary input is given precedence over direct distance input by default. Set this bit if you wish to force AutoCAD to evaluate user input as direct distance input. Note that legal point input from the keyboard always takes precedence over either direct distance or arbitrary input.

    512(bit 9) If set before a call to getpoint or getcorner, a temporary UCS will be established when the cursor crosses over the edge of a planar face of a solid. The temporary UCS is reset when the cursor moves off of a face. It is dynamically re-established when the cursor moves over a different face. After the point is acquired, the dynamic UCS is reset to the current UCS. This functionality is not enabled for non-planar faces such as the side of a cylinder.

    1024(bit 10) When calling getdist, getangle, getorient, getpoint, or getcorner, you may not want the distance, angle, orient, point, or corner to be influenced by ortho, polar, or otracking in the Z direction. Setting this bit before calls to any of these functions will temporarily disable ortho, polar, and otracking in the Z direction. This is useful when you create 2D entities such as PLINE, ARC, or CIRCLE, or when you use the ARRAY command, which creates only a 2D array. In 2D-only commands it can be confusing and error-prone to allow 3D points to be entered using ortho Z, polar Z, or otrack Z.
      

    string

    A string representing a series of keywords. See “Keyword Specifications” for information on defining keywords.
     
     
    as describled above bit code can be used individual or added togather. for example if you do not want to Get function to accept null and zero input, your syntax may as following
     
    (initget 3)
    (setq age (getint "Enter Your Age :"))
     
    in this example you notice that there is no bit value of 3 for initget. 3 is compination of bit 0 and bit 1 (1+2). it prevent user by entering null or zero value. but not all of these bit values are used with all Get Functions. here are list of which bit values of Getint are used with which Get Function.
     
    Getint          : 1,2,4,128
    Getreal         : 1,2,4,128
    Getdist         : 1,2,4,32,64,128,256,1024
    Getangle       : 1,2,32,128,256,1024
    Getorient      : 1,2,32,128,256,1024
    Getpoint       : 1,8,32,128,256,512,1024
    Getcorner     : 1,8,32,128,256,512,1024
    Getkword      : 1,128
     
    now we look example of initget. suppose you ask user for distance in your program. u may use Getdist with two point requirement. at this point suppose user wants to input distance value by keyboard. this will be possible with use with initget. thus initget allow user to accept inputs from keyboard and mouse.
     
     
    Example
     
    (setq pt1 (getpoint "Select point :"))
    (initget 1)
    (setq dist1 (getdist pt1 "specity second point :"))
     
    when you see prompt specity second point : at command line just type 25 other than select point on screen. when you enter 25 the getdist function ends and value 25 is assigned to variable dist1. check value of dist1 by entering !dist1 at command line
     
     
    Getkword
     
    The syntax for Initget is
     
    (getkword [msg])

    Valid keywords are set prior to the getkword call with the initget function. The user cannot enter another AutoLISP expression as the response to a getkword request.

    Arguments

    msg

    A string to be displayed to prompt the user; if omitted, getkword does not display a prompting message.

     
    if such a situation where user is asked to choose one of many options. you can use strings in initget function. let's look
     
    (initget "Word Autocad Excel")
    (setq txt (getkword "Enter your Choice [Word / Autocad / Excel] :"))
     
    When you enter above two sentence on command line the following prompt will shown
     
    Enter your Choice [Word / Autocad / Excel] :
     
    now user have three choices, but one thing is important, that is capitalization of keyword. The required portion of the keyword is specified in uppercase characters, and the remainder of the keyword is specified in lowercase characters. The uppercase abbreviation can be anywhere in the keyword (for example, "LType", "eXit", or "toP").
     
    in our example when user type only a or A the stirng Autocad is assigned to variable txt. and if user type except w a e or W A E the message Invalid option keyword will appear and ask again to choose one of the option. the user may enter the whole string also like autocad.