A BETTER VIEW (view.lsp)

The scenario: you’re restoring a saved view in that huge drawing and suddenly you’re lost — you’re nowhere near where you expected to be. Someone has overwritten your saved view and it really isn’t their fault — AutoCAD doesn’t warn you that you’re overwriting an existing view as it does with blocks. This month’s LISP File is a replacement for AutoCAD’s VIEW command that works how it should have in the first place and warns the user if they are about to overwrite an existing view.

The Listing

After the program description, there are two lines of code before the DEFUN statement. Since they are not inside a DEFUN, they will run when the program is loaded. The code undefines the standard View command and informs the user that View is being redefined.

The program is then given its name, VIEW, and the variables it uses are localized. The current setting for the Cmdecho Setvar is then saved to variable CMD2 for restoration at the end of the program. The next line changes the Cmdecho Setvar to zero so as to suppress echoing of command sequences to the command line. The Initget function is then used to initialize five keywords as permissible responses to the following prompt, the response being saved to variable KWD2. The omission of an integer in Initget’s argument list allows the user to hit [RETURN] which would end the program without any action.

The Cond function is then started which will check the value stored in KWD2 and then run the appropriate routine. It first checks to see if the user wishes to save a view. If so, the user is prompted for a view name which is stored in variable VN2.

An If is coupled with a TBLSEARCH which searches the drawing’s View table for the view name in VN2. If found, the IF’s then-expression, grouped by a PROGN, will run. This starts by initializing allowable keywords for the following prompt which warns the user that the proposed view name already exists and asks if they would like to redefine (or overwrite) it. Note again that Initget allows the user to hit [ENTER]. Coupled with the following If’s check for KWD3 being not equal to "No", this effectively makes "Yes’ the default value. The IF’s then-expression would save the view.

After closing the IF and the PROGN for the previous IF’s then-expression, its else-expression, which would run when no view of that name already existed, simply saves the view. If the user had entered "No", then the program would have jumped out of the COND without taking any action.

The second part of the COND checks to see if the value in KWD2 is "Window". If so, the user is asked for a view name, the view table is searched and the user is asked to redefine if the view name is found. If it is to be redefined, two points are requested. Note that the second point uses the GETCORNER function with the first point supplied as the first argument. This produces a rectangle on screen identical to AutoCAD’s Window rectangle and provides an accurate reproduction of the ‘real’ View command. These points are supplied to the COMMAND function to save a view using those points for the window.

Its else-expression, run when no view of that name exists, also requests the two points and saves the window created by the two points.

The third part of the COND uses T as the first argument to force this to run if either of the two earlier parts didn’t run i.e. the user entered anything other than "Save" or "Window". This simply runs the View command with only the value of KWD2 as the first option supplied to the command. This leaves it ‘open’ to run as the normal View command.

Once the COND is finished, the Cmdecho Setvar is restored to its original value and the PRINC function prevents the value of Cmdecho from being printed on the command line.
 

©1996-2001 ZOTO Technologies