AutoCAD: Secrets Every User Should Know

The IF function is often described by programmers as an IF - Then - Else function. It s used all the time to check a condition and have the program respond differently depending on whether the condition is true or false. An IF function has either one or two arguments. If it has one argument, and a condition is true, the function that follows is executed, and the program continues. If the condition is false, the program ignores the next function and continues on.
When an IF statement has two arguments, the first is executed when the IF function returns true, and the second argument is ignored. When the IF condition isn t true, the first function is ignored, and the second function is executed; then the program continues. The best way to understand it is to write a short program to create a toggle.
The IF function can be used to toggle a variable turn it on or off depending on its current state like a three-way light switch. Let s create a command that turns the UCS icon on if it s off and off if it s on. The visibility of the UCS icon is controlled by the variable UCSICON. Although UCSICON has four settings, you ll use only two of them: 0 to turn it off, and 3 to turn it on and place it at 0,0. See Listing 9.5.
ui.lsp ui.lsp (defun C:UI...