Getreal, getdist etc.) with the exception of getstring However, the methods & logic illustrated above could equally be applied to the other getXXX user input functions (e.g. In all of the above the examples, I have used the getkword function to prompt the user to select one of a predefined set of options, The last selected option as held by the global:ans variable is used as the default. Therefore, in the expressions that follow, If the program is then run a second time, the variable global:ans now has a value, and so the test expression Return nil and the global:ans variable will retain its existing value as the default option Is updated to store the new input (even if the user may have explicitly selected the same option as the default).Ĭonversely, if the user has pressed ENTER at the prompt, the getkword function will the getkword function has returned a non-nil value), the global variable global:ans
The if statement which follows reverses the logic used in the previous examples: if the user has responded with If statement will bind the value "Alpha" to it - this will be the first-time default. Upon the first run of the program, the variable global:ans will be nil and so the Upon the first run of the program there is a default to be offered to the user. In the above code, the variable global:ans is first checked for a non-nil value: this is to ensure that, ( if ( null global:ans ) ( setq global:ans "Alpha" ) ) ( initget "Alpha Beta Gamma" ) ( if ( setq tmp ( getkword ( strcat "\nChoose : " ))) ( setq global:ans tmp ) ) Input, since the only way the user can bypass the prompt is to exit the program using ESC. User to make a selection from the available options hence in this case no conditional error trapping is required to ensure user
#Autocad lisp setq getreal pressing enter returns value to 0 code#
I use the initget function with bit code 1 to force the This is the simplest case in which there is no default option available. Using duplicate unlocalised variable names between programs. Read my tutorial on Localising Variables to understand the possible consequences of I would note that the prefixes are used for no other purpose: in AutoLISP, they constitute standard variable names. To indicate where global variables are utilised, the variable names are prefixed with global: thisįurthermore decreases the risk of variable names clashing with unlocalised variables from other programs. In the examples that follow, global variables are used to effectively 'remember' a default option after program completion. In the above example, Options 1, 2 & 3 are availableįor user selection with Option 1 as a default option - selected upon the user pressing Enter.