JimYuan's Blog

Sharing the things I learned

0%

VisualLISP_GardenPath

Tutorial: Garden Path (Visual LISP IDE)

Reference

  • The Visual LISP® environment is introduced.
  • ActiveX® and Reactor functions of AutoLISP are demonstrated, as well as several other extensions to the AutoLISP language provided with Visual LISP.

There are two possible executino contexts for this tutorial:

  • The application may be run as interpreted LISP in piecemeal files and/ or functions that are loaded into a single document.
  • Or, the program code can be compiled into a VLX application, denoted by a *.vlx executable. A VLX operates from a self-contained namespace that can interact with the application-loading document.

Lesson 1: Designing and Beginning the Program(Visual LISP IDE)

Reference

Defining Overall Program Goals

Task

  • Given a start point, an endpoint, and a width, draw a rectilinear boundary. The boundary can be at any 2D orientation. There should be no limit on how large or small it can be.
  • Prompt the user for tile size and tile spacing values. The tiles are simple circles and will fill the boundary but must not overlap or cross the boundary.
  • Place the tiles in alternating rows.

Example Location can be found in:
C:\Program Files\Autodesk\AutoCAD 2022\Tutorial\VisualLISP

Getting Started With Visual LISP

First, it helps to demonstrate what can happen when Visual LISP is waiting for contorl to return from AutoCAD.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;; Function C:GPath is the main program function and defines the 
;;; AutoCAD GPATH command.
(defun C:GPath ()
;; Ask the user for input: first for path location and
;; direction, then for path parameters. Continue only if you have
;; valid input.
(if (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!")
)
(princ "\nFunction cancelled.")
)
(princ "\nIncomplete information to draw a boundary.")
)
(princ) ; exit quietly
)
;;; Display a message to let the user know the command name.
(princ "\nType gpath to draw a garden path.")
(princ)
  • defun: declare the funcation
  • C:GPath : Command, and the name is GPath
  • gp:getPointInput and getDialogInput: These function names are prefixed with gp: to indicate they are specific to the graden path applcation. This is not a requiremnet
  • The final princ without a string argument forces the program to exit quietly.

Filling the Gaps in the program

  • pg:getPointInput
  • pg:getUserInput
  • gp:drawOutline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;; 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 through 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
)
  • The letter T is the symbol for “true” in AutoLISP
  • The way gpmain.lsp is structured, each input function it calls must return a value other than nil(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.)