The Beginning.
So, you want to start coding using Visual Lisp? Two things. First you
really need to have a good understanding of AutoLisp before you carry on
with this Tutorial. VLisp is not an replacement for AutoLisp, it is an
extension to it. Standard AutoLisp is used extensively throughout Visual
Lisp, so a good knowledge is a necessity. Secondly, in this tutorial I am
not going to delve deep into the why's and where's of VLisp. The intention
is to give you a basic grounding into what VLisp can do and how to go
about doing it. For example, some of my terminology may not be technically
correct as I've tended to convert some things to layman terms for clarity
and ease of understanding. Don't worry, we'll correct all that in future
tutorials.
O.K. are you ready to start? Right, fire up AutoCAD with a blank
drawing and open the Visual Lisp Editor. You can write Visual Lisp using
Notepad just like AutoLisp if you wish, but I prefer to use the Visual
Lisp Editor as we can, and will, use the "Watch" and the
"Inspect" windows.
Close the Editor window, leaving the "Console" window open, and
then open the "Watch" window. Right, we're ready to start.
Type this at the Console prompt and then press enter :
_$ (vl-load-com)
Did you notice that nothing happened? Before you can use the VLisp
functions with AutoLisp, you need to load the supporting code that enables
these functions. The (vl-load-com) function first checks if the VLisp
support is already loaded; if so, the function does nothing. If the
functions are not loaded, (vl-load-com) loads them. Pretty important I
would say!
"All applications that use
Visual Lisp should begin by calling (vl-load-com). If (vl-load-com) is not
loaded, the application will fail."
After loading the Visual Lisp functions, the next step is to establish
communication with the AutoCAD Application object.
Think of a filing cabinet. The cabinet itself is your computer and one of
the filing cabinet drawers is AutoCAD. We are going to open the AutoCAD
drawer to have a look at what is inside.
To establish this connection, we use the (vlax-get-acad-object) function.
Type this at the Console prompt and then press enter :
_$ (setq acadObject (vlax-get-acad-object))
Now, double click on the variable "acadObject" in the Console
window to select it, and then add it to the "Watch" window. It
should look something like this :
We are now looking at the Acad Application object. Double
click on the "ACODBJECT" in the "Watch window to open the
"Inspect" window :
This is a list of all the Objects within the AutoCAD Application
Object.
Now double click on <Preferences> :
This is all the Objects within the AutoCAD - Application - Preferences
object . Now double click on <Files> :
Compare this list with what you see when you open the
Options-Files Dialog :
Pretty much the same hey? On the next page we'll have a
look at how we can access these Objects programatically.
|