Is LISP Out of a Job? No Way!1 Jul, 2002 By: Bill Kramer
There are a lot of tools for customizing AutoCAD, so programmers often want to know which tool is the best for the job and which to learn at the exclusion of all others. In response, I normally ask, "Do you own a set of tools for doing repairs around the house or on a car? And if so, do you have only one screwdriver, one set of pliers, and a single saw for cutting everything?" The fact is, you'll need not just one but a good selection of tools to do home or car repair. The same holds true for programming AutoCAD.Learning the Ropes
So where do you start and how do you learn the basics? If you are the type that can learn from books and examples, there is no shortage of reference material online or in print. If you prefer the classroom environment, you can locate classes from various training centers and schools that provide continuing education. These classes may be enough to get you started or point you in the right direction, but only experience (plenty of it) will give you sufficient skill to program fancy applications.
|Table 1. Picking the Right Tool for Your Applications|
|Applications||Menu Diesel||Visual LISP||VBA ActiveX||Object ARX|
|Automating a sequence of commands||Yes||Yes||No||Yes *|
|Building custom drawing objects||No||No||No||Yes *|
|Chartsdrawing the outline||Yes||Yes||Yes||Yes *|
|Chartsinserting data||Varies||Yes||Yes||Yes *|
|Chartsoptimizing for view||Varies||Yes||Varies||Varies|
|Command sequences||Yes||Yes||Yes||Yes *|
|Complex interface (lots of dialog boxes)||No||Varies||Yes||Yes *|
|Complex interface (lots of graphic selections)||Yes||Yes||Varies||Varies|
|Context activated menu of options||Yes||Varies||No||Varies|
|Controlling a smart drawing||No||Varies||Varies||Yes|
|Creating a smart drawing||No||Yes||Yes||Yes|
|Drawing preparations (paper space)||Yes||Yes||Varies||Varies|
|Improved menu system||Yes||Varies||No||No|
|Integration with external Active X objects||No||Varies||Yes||Yes|
|Integration with external database||No||No **||No **||Yes *|
|Integration with external text files||No||Yes||Yes||Yes|
|Intercept AutoCAD commands (PLOT, SAVE)||No||Varies||Varies||Yes *|
|Intercept AutoCAD Edit commands||No||Varies||Varies||Yes *|
|Number crunching from data in drawing||No||Varies||Varies||Yes *|
|Open and close multiple drawings||No||No||Yes||Yes *|
|Parameter-based drawing||No||Yes||Yes||Yes *|
|Reacting to AutoCADdrawing changes||No||Yes||Yes||Yes *|
|Spreadsheet interface (generation of files)||No||Yes||Yes||Yes|
|Spreadsheet interface (integrate via ActiveX)||No||Varies||Yes||Yes *|
|Title block generation||Yes||Yes||Varies||Varies|
|Work with multiple files/share data||No||No||Yes||Yes *|
|Yes: Works well for this sort of application.
No: Does not work well or not at all for this type of application.
Varies: Works well for simple variations; not as well for complicated applications.
* ObjectARX is not as easy to work with as the other alternatives. It may require additional effort or utilities.
** External databases vary. If the one you are using comes with an ActiveX interface then both Visual LISP and VBA can interface with it. The languages do not support any advanced database systems directly except through ActiveX automation. Visual C++ database support is also dependent on the database system; however, more alternatives exist with ObjectARX, which makes it earns the Yes rating.
If you are new to programming, start with the AutoCAD menu-system. Productivity can be gained by simply changing the AutoCAD menu. You know what commands you use and how frequently you use them. Simply arrange the menu to make them easier to select. As you manipulate the menu, you will become aware of DIESEL, a programming language that allows you to employ variables and apply some logic to the menu macros.
Experienced programmers will find the menu system to be of interest; but, unless you use AutoCAD on a regular basis, it is best to leave the standard menu alone and simply add new menu elements. Menus can be programmed using DIESEL and Visual LISP. I prefer the latter but you can accomplish a great deal in DIESEL if your application is based on AutoCAD-command sequences only.
As to the other programming languages available, only ARX (in C++ environment) provides easy access to the menu system. The ActiveX interfaces and VBA system included with AutoCAD allow you to manipulate the menu objects but they are not well suited to receive input from the menu system. Instead, you are expected to launch the application and then use dialog boxes for input. There are many books on the subject of Visual C++ and VB/VBA. However, only certain books will relate to AutoCAD. Most of these assume you have a working knowledge of BASIC or C++.
Perhaps the only place to get a variety of classes directly related to programming AutoCAD using VB, VBA, and C++ is Autodesk University or the CAD Cruise. Both offer classes ranging from beginner to advanced levels. If some universities and training centers do offer similar classes, they are worth seeking out; they will most likely be available more often than once a year.Relative Strengths
Okay, so you want to write an AutoCAD-based application. Certain language environments are better suited for certain application types, as shown in Table 1.
Each language has an advantage over the others in certain areas. For example, the VBA options are strong at ActiveX-type integration and manipulating several drawings at once; ObjectARX is better equipped to manipulate multiple drawings; Visual LISP is well suited to single-drawing sessions. So if your application requires opening multiple drawings and sharing information actively among them, you should be looking at ObjectARX and VBA. It doesn't mean Visual LISP cannot be used; it just requires substantially greater effort.
Glancing at Table 1, you may think Object ARX is the ideal choice since it seems to do everything. The problem is the learning curve; if you are not a skilled C++ programmer, you'll find ObjectARX difficult. C++ is a complex language with many tools, provided in the form of libraries and objects. Once you know C++, Object ARX is easy. The key is to learn how to manipulate the library.
To use Object ARX you must purchase additional tools not supplied with AutoCAD. You will want to obtain a C++ compiler and linker to build the ARX modules. ARX modules are specialized DLL programs that only work with AutoCAD; they require you to use the Autodesk-supplied libraries. Object ARX is compiled; that means a future release of AutoCAD might require you to re-compile using a newer version of the libraries and C++ compiler system. Because Object ARX resides within AutoCAD, closer than any other programming options, it is easier to get yourself into trouble. This is why Object ARX is often not the most attractive solution except for the most serious applications.
Because a lot of people already know BASIC, most programmers favor VBA and ActiveX customization. With these languages, you can apply your knowledge of the BASIC language to automating AutoCAD. But beware--the ActiveX components of AutoCAD are among the newest in the customization toolkit. The way things are done is subject to change. You may also suddenly encounter something missing or behaving in an unexpected manner. The only frustration I've encountered with VBA has been things not working quite as they are expected to (for instance, getting an automation error when the operator selects an item from an AutoCAD-screen menu). It's easy to program around the problem once you find it; however, knowing the program might be changed in the future makes it frustrating when developing tools.
Visual LISP works well for a wide variety of applications even though its unusual syntax is somewhat difficult to learn, even for experienced programmers. Visual LISP acts as a bridge between the primary operator interface of the menu and other areas of the computer. It is not difficult to integrate Visual LISP with Object ARX (C++ is used to create new functions for LISP) and Visual LISP provides the best way to tie a VBA macro into a menu.Integration Solutions
The best applications are created using an integration of various tools. Just as you cannot always repair something with only a screwdriver or a hammer, you cannot always achieve the optimal solution in AutoCAD using one tool. You might use a command menu for editing and manipulating specific graphics; the command might contain Visual LISP and DIESEL elements; those might call up VBA or Object ARX elements. The communication between the various environments is not always obvious, and it's not always a two way street; you can start a VBA macro from Visual LISP but the two run at the same time. That means you should chain the activities instead of nesting them.
It's not a good idea to chain back and forth multiple times in an application. Chaining should be minimized to accomplish a smooth integration between the two environments. The only exception is Object ARX and Visual LISP. Here, Visual LISP calls up Object ARX functions, which have access to the Visual LISP variables and symbols. Object ARX cannot start a Visual LISP function in such a state, but it can send a command string to start Visual LISP when started as a command itself.
So which is best to learn? All of them. But start with the one that will solve your dilemma best and learn as much as you can about the different options. What looks good at first may actually be a problem down the road. That is why, if you really press me for a recommendation, I say Visual LISP: it has the best track record; it has been around the longest; it is powerful and yet easy to learn. Until next time, keep on programmin'!
Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD how-to, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's Tips & Tricks Tuesdays free e-newsletter and we'll notify you every time a new video tip is available. All exclusively from Cadalyst!
AutoCAD 2013 Service Pack 2 has been Released 20 May, 2013
Webcast Replay: Flexible Design with PTC Creo 20 May, 2013
Discover and Fix Your Vibration Vulnerability with SolidWorks Simulation 17 May, 2013