Filling the Gaps in the Program

AutoCAD Visual LISP

 
Filling the Gaps in the Program
 
 
 

For the code in this new file to work correctly, you must write three more function definitions. The main garden path code contains calls to three custom functions:

  • gp:getPointInput
  • gp:getUserInput
  • gp:drawOutline

For now, you will just write stubbed-out function definitions. A stubbed-out function serves as a placeholder for the complete function that is to follow. It allows you to try out pieces of your code before adding all the detail needed to complete the application.

To define stubbed-out functions for the application

  1. Position your cursor at the top of the program code in the text editor window and press ENTER a couple of times to add blank lines.
  2. Enter the following code, beginning where you inserted the blank lines:
    ;;; Function gp:getPointInput will get path location and size
    (defun gp:getPointInput	()
      (alert
        "Function gp:getPointInput will get user drawing input"
      )
      ;; For now, return T, as if the function worked correctly.
      T
    )
    ;;; Function gp:getDialogInput will get path parameters
    (defun gp:getDialogInput ()
      (alert
        "Function gp:getDialogInput will get user choices via a dialog"
      )
      ;;For now, return T, as if the function worked correctly.
      T
    )
    ;;; Function gp:drawOutline will draw the path boundary
    (defun gp:drawOutline ()
      (alert
        (strcat "This function will draw the outline of the polyline" 
    	    "\nand return a polyline entity name/pointer."
        )
      )
      ;; For now, simply return a quoted symbol. Eventually, this
      ;; function will return an entity name or pointer.
      'SomeEname
    )

Right before the end of each input function is a line of code that contains only a T. This is used as a return value to the calling function. All AutoLISP functions return a value to the function that called them. The letter T is the symbol for “true” in AutoLISP, and adding it causes the function to return a true value. The way gpmain.lsp is structured, each input function it calls must return a value other than nil (which indicates “no value”) for the program to proceed to the next step.

An AutoLISP function will, by default, return the value of the last expression evaluated within it. In the stubbed-out functions, the only expression is a call to the alert function. But alert always returns nil. If this is left as the last expression in gp:getPointInput, it will always return nil, and you will never pass through the if to the gp:getDialogInput function.

For a similar reason, the end of the gp:DrawOutline function returns a quoted symbol ('SomeEname) as a placeholder. A quoted symbol is a LISP construct that is not evaluated. (If you are curious about how the LISP language works, there are a number of good books available, mentioned at the end of this tutorial.)