Examining the gp:getPointInput Function

AutoCAD Visual LISP

 
Examining the gp:getPointInput Function
 
 
 

When you ran the gp:getPointInput function, control was automatically passed from VLISP to AutoCAD. You responded to three prompts, after which control was passed back from AutoCAD to VLISP, and a T symbol displayed in the Console window.

Within the program, here's what happens:

  1. VLISP waits for you to pick the first point.
  2. When you pick the first point, the program stores the value of your selection (a list containing three coordinate values—an X, Y, and Z value) into the StartPt variable.
  3. The first if function examines the result to determine whether a valid value was entered or no value was entered. When you pick a start point, control is passed to the next getpoint function.
  4. When you pick an endpoint, the point value is stored in the Endpt variable.
  5. The result of this statement is examined by the next if statement, and control is passed to the getdist function.
  6. The getdist function acts in a similar fashion when you pick a point on the screen or enter a numeric value. The result of the getdist function is stored in the HalfWidth variable.
  7. Program flow reaches the T nested deeply within the function. No other functions follow this, so the function ends, and the value T is returned. This is the T you see at the Console window.

You need some way to return values from one function to another. One way to do this is to create a list of the values retrieved from gp:getPointInput, as highlighted in the following code:

(defun gp:getPointInput ( / StartPt EndPt HalfWidth )
  (if (setq StartPt (getpoint "\nStart point of path: "))
     (if (setq EndPt (getpoint StartPt "\nEndpoint of path: "))
       (if (setq HalfWidth (getdist EndPt "\nhalf-width of path: "))
 (list StartPt EndPt HalfWidth)
             )
     )
  )
)

Copy this version of gp:getPointInput into the Console window and press ENTER. Here's an opportunity to try another feature of the Console window.

To use the Console window history feature to run gp:getPointInput

  1. Press TAB.

    This invokes the Console history command, cycling through any commands previously entered in the Console window. If you go too far, press SHIFT + TAB to cycle in the other direction.

  2. When you see (gp:getPointInput) at the Console prompt, press ENTER to execute the function once again.
  3. Respond to the prompts as before.

The function returns a list containing two nested lists and a real (floating point) value. The return values look like the following:

((4.46207 4.62318 0.0) (7.66688 4.62318 0.0) 0.509124)

These values correspond to the StartPt,EndPt, and HalfWidth variables.