# Revising the Program Code

Revising the Program Code

Now that you've seen how to use association lists in AutoLISP code, you can use this method in writing the completed version of the gp:getPointInput function. Using the following code, replace or modify the version of gp:getPointInput you previously saved in gpmain.lsp.

NoteIf you need or want to type the code into gpmain.lsp, rather than copy it from another file, you can save time by leaving out the comments (all lines that begin with semicolons). But don't get used to the idea of writing code without comments!
`;;;--------------------------------------------------------------;`
`;;;     Function: gp:getPointInput                               ;`
`;;;--------------------------------------------------------------;`
`;;;  Description: This function asks the user to select three    ;`
`;;;               points in a drawing, which will determine the  ;`
`;;;               path location, direction, and size.            ;`
`;;;--------------------------------------------------------------;`
`;;;  If the user responds to the get functions with valid data,  ;`
`;;;  use startPt and endPt to determine the position, length,    ;`
`;;;  and angle at which the path is drawn.                       ;`
`;;;--------------------------------------------------------------;`
`;;;  The return value of this function is a list consisting of:  ;`
`;;;   (10 . Starting Point) ;; List of 3 reals (a point) denoting ;`
`;;;                         ;;  starting point of garden path.   ;`
`;;;   (11 . Ending Point)   ;; List of 3 reals (a point) denoting ;`
`;;;                         ;;  ending point of garden path.     ;`
`;;;   (40 . Width)          ;; Real number denoting boundary     ;`
`;;;                         ;;  width.                           ;`
`;;;   (41 . Length)         ;; Real number denoting boundary     ;`
`;;;                         ;;  length.                          ;`
`;;;   (50 . Path Angle)     ;; Real number denoting the angle    ;`
`;;;                         ;;  of the path, in radians.         ;`
`;;;--------------------------------------------------------------;`
`(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: "))`
`         ;; if you've made it this far, build the association list`
`         ;; as documented above.  This will be the return value`
`         ;; from the function.`
`         (list`
`           (cons 10 StartPt)`
`           (cons 11 EndPt)`
`           (cons 40 (* HalfWidth 2.0))`
`           (cons 50 (angle StartPt EndPt))`
`           (cons 41 (distance StartPt EndPt))`
`) ) ) ) )`

Next, you need to update the main function, C:GPath, in gpmain.lsp. Modify it to look like the following code:

`(defun C:GPath (/ gp_PathData)`
`  ;; Ask the user for input: first for path location and`
`  ;; direction, then for path parameters.  Continue only if you`
`  ;; have valid input.  Store the data in gp_PathData.`
`  (if (setq gp_PathData (gp:getPointInput))`
`    (if      (gp:getDialogInput)`
`      (progn`
`            ;; At this point, you have valid input from the user.`
`            ;; Draw the outline, storing the resulting polyline`
`            ;; pointer in the variable called PolylineName.`
`            (setq PolylineName (gp:drawOutline))`
`            (princ "\nThe gp:drawOutline function returned <")`
`            (princ PolylineName)`
`            (princ ">")`
`            (Alert "Congratulations - your program is complete!")	`
`        ) ;_ end of progn`
`       (princ "\nFunction cancelled.")`
`    ) ;_ end of if`
`    (princ "\nIncomplete information to draw a boundary.")`
`  ) ;_ end of if`
` (princ)				; exit quietly`
`);_ end of defun`

If you are copying and pasting the code, add the following comments as a header preceding C:GPath:

`;;;**************************************************************;`
`;;;     Function: C:GPath        The Main Garden Path Function   ;`
`;;;--------------------------------------------------------------;`
`;;;  Description: This is the main garden path function. It is a ;`
`;;;               C: function, meaning that it is turned into an ;`
`;;;               AutoCAD command called GPATH. This function    ;`
`;;;               determines the overall flow of the garden path ;`
`;;;               program.                                       ;`
`;;;**************************************************************;`
`;;; The gp_PathData variable is an association list of the form: ;`
`;;;  (10 . Starting Point) - List of 3 reals (a point) denoting  ;`
`;;;                           starting point of the garden path. ;`
`;;;  (11 . Ending Point)   - List of 3 reals (a point) denoting  ;`
`;;;                           endpoint of the garden path.       ;`
`;;;  (40 . Width)          - Real number denoting boundary       ;`
`;;;                           width.                             ;`
`;;;  (41 . Length)         - Real number denoting boundary       ;`
`;;;                           length.                            ;`
`;;;  (50 . Path Angle)     - Real number denoting the angle of   ;`
`;;;                           the path, in radians.              ;`
`;;;  (42 . Tile Size)      - Real number denoting the size       ;`
`;;;                           (radius) of the garden path tiles. ;`
`;;;  (43 . Tile Offset)    - Spacing of tiles, border to border. ;`
`;;;  ( 3 . Object Creation Style)                                ;`
`;;;                        - Object creation style indicates how ;`
`;;;                          the tiles are to be drawn.  The     ;`
`;;;                          expected value is a string and one  ;`
`;;;                          one of three values (string case    ;`
`;;;                          is unimportant):                    ;`
`;;;                              "ActiveX"                       ;`
`;;;                              "Entmake"                       ;`
`;;;                              "Command"                       ;`
`;;;  ( 4 . Polyline Border Style)                                ;`
`;;;                        - Polyline border style determines    ;`
`;;;                          the polyline type to be used for    ;`
`;;;                          path boundary.  The expected value  ;`
`;;;                          one of the following (string case is;`
`;;;                          unimportant):                       ;`
`;;;                              "Pline"                         ;`
`;;;                              "Light"                         ;`
`;;;**************************************************************;`

To test the code revisions

1. Save the updated file.
2. Use the Check feature to search for any syntactical errors.
3. Format the code, to make it more readable.
4. Load the code, so that VLISP redefines the earlier versions of the functions.
5. To run the program, enter (c:gpath) at the Console prompt.

If the program does not run successfully, try fixing it and running it again. Repeat until you are too frustrated to continue. If all else fails, you can copy the correct code from the Tutorial\VisualLISP\Lesson2 directory.