VBA tutorial
VBA in IntelliCAD
Visual Basic for Applications (VBA) is a programming language found in a number of Microsoft Windows applications. It has been developed by Microsoft as a variation of its Visual Basic programming language, able to be imbedded as a component into other applications to provide a Windows-compatible programming environment.
The current versions of both AutoCAD and IntelliCAD now provide VBA as a programming option. While the VBA implementation in AutoCAD has a reasonable amount of technical information and on-line help available, similar information for IntelliCAD is not so easy to obtain. This article is intended to provide an introduction to VBA for IntelliCAD and give some basic information about how to install it, and use it.
Why use VBA?
Perhaps the first question to be addressed is, why should one use VBA for programming in IntelliCAD? Here, we can address both AutoCAD and IntelliCAD equally, as the same reasons apply to both programs. Most development in these programs is usually performed using ILISP in IntelliCAD (AutoLISP in AutoCAD), an interpretive programming language which offers great flexibility. The biggest drawback with LISP is that it is slow. If substantial processing of data is required, this can take a lot of time to complete. Also, to implement any form of dialogue box requires interfacing with the DCL development system and this can be quite messy.
For professional developers, more serious work can be done in SDS in IntelliCAD (or ObjectARX in AutoCAD). This involves writing programs, usually in the C language, then compiling these with certain supplied custom libraries to obtain a program module which can run in association with the CAD program. Such applications run very much faster than LISP and can call upon all the features available in the C programming language. However, development in this manner usually requires a much higher level of programming knowledge that that held by typical CAD users and the need to obey specific requirements when interfacing your application to the host CAD program.
VBA falls neatly into the middle of these two options. It is reputed to be only marginally slower in processing speed than ARX, and only slightly more complex to learn than LISP. In fact, the real issue is one of difference rather than complexity. Someone who has only ever used LISP as a programming tool, will find VBA attacks things from a completely different direction. In terms of program code it is probably much easier than LISP, with the IDE (Integrated Development Environment, or Editor screen) presenting the most obvious difference. VBA also provides very easy mechanisms to add full featured dialogue boxes and other user interface functions to give programs a very professional look.
Implementing VBA
Not all implementations of IntelliCAD support VBA, you need to make sure that you purchase a Professional Version of IntelliCAD (with VBA) if you want to implement VBA applications. Although earlier implementations of VBA in some IntelliCAD variants required special installation, VBA is installed 'out of the box' in our version of intelliCAD Pro.
Set user level
There is one final step to perform before running a VBA application. It will be necessary, assuming you're using the standard IntelliCAD screen menu, to select OPTIONS from the TOOLS menu pulldown. Then, on the GENERAL tab, set the Experience Level to "Advanced". This will cause a "Visual Basic" menu entry to be available about midway down the TOOLS pulldown.

Accessing VBA
While the VBA Editor can be directly accessed from the TOOLS menu, it can also be called from the program's command line. There are several commands available, all named to approximately correspond with the equivalent VBA commands to be found in AutoCAD, although in some cases their functions are quite different. These commands are,
VBA or VBAIDE - call up the VBA Editor Screen
VBALOAD or VBAUNLOAD - call up the Add In Manager Dialogue Box
VBARUN - call up the dialogue box to run a VBA macro (program)
You can also use the variation, "-VBARUN" to call up a program without displaying the dialogue box on the screen.
You may need to change the Security Level and enable macros in your copy of IntelliCAD in order to run VBA. You can stop IntelliCAD dispalying the dialog box seen below by setting the Security level to low. Only do this if you are confident that your virus protection and firewall systems provide adequate protection.

In short, you use VBA to get the Editor up for programming, and use VBARUN to cause the program to execute. The figure below shows an example of using the VBA command.

The figure below shows the result following the VBA command when a drawing containing a VBA project application is loaded.

The VBALOAD/VBAUNLOAD options bring up a menu which appears to involve the loading of external "Add In" program modules (DLL's), which can be created in a standalone copy of Visual Basic, and for which we still need to learn more. In general there is a lack of any useful documentation for much of the IntelliCAD VBA implementation, but any prior knowledge of Visual Basic is a major benefit.
The final subject we will cover here is how to get a VBA application to run from a menu. Although we've not touched on any programming here, we will address some examples of VBA applications in the next installment of these articles.
We will prepare a small (one item) pulldown menu to load and execute a VBA application. This following menu code is for a simple menu, to be appended to the existing IntelliCAD menu, which will run an application function called "LoadApp" located in the "CommonProjects.vbi" file in IntelliCAD (more about the "CommonProjects" file in the next instalment).
***MENUGROUP=Test
***POP1
[Test]
[Run Application]^C^C-VBARUN;LoadApp;
When this menu file is appended (import the file with the "append" check box set, using the CUSTOMISE option in the TOOLS pulldown) to your existing menu, a new menu item called "Test" will be available. When this is selected an option called "Run Application" will be presented. If this is selected a function called "LoadApp" will be run from the program code stored in the "CommonProjects.vbi" file located in the IntelliCAD base directory. The suffix "VBI" is given to IntelliCAD VBA programs. These can be associated with a specific drawing file, in which case a file with the same name as the drawing file will be created, but with the "VBI" file suffix, or they can be common to all drawings, in which case they are
placed in the "CommonProjects" file.
Although we've covered several unrelated, and possibly confusing, items here, anyone with familiarity in Visual Basic should now have enough information to be able to start exploring VBA in IntelliCAD. For the rest, there will be a few follow up articles were we will introduce the use of Visual Basic for Applications and how it can be applied to perform practical operations within IntelliCAD.