Return to the Design Drawing homepage SearchSubscribe

Click here!

[FrontPage Include Component]

VBA Preview in IntelliCAD 98

Frank Zander

Article

Frank Zander explores some of the working and non-working parts of IntelliCAD's Preview VBA and shows how to create a small  program using IntelliCAD's working VBA code.
IntelliCAD 98, VBA

.

VBA has fired the curiosity of many IntelliCAD users. In Part I, Frank Zander explores some of the working and non-working parts of IntelliCAD's Preview VBA. For the adventurous, in Part II he shows how to create a small 'rubber-stamp' program in IntelliCAD's working VBA environment

What is VBA anyway?
Visual Basic for Applications (VBA) allows Visual Basic (VB) programmers to work in a familiar Visual Basic environment. Those not familiar with the Visual Basic environment will find that the interface is easy to use and straight forward.

The preview edition of IntelliCAD 98’s VBA is a limited subset of the available Objects, Methods and Properties. All of the IntelliCAD Objects, Methods and Properties are accessible to the VBA Object Browser by pressing F2 from within the VBA IDE. The Objects are, for the most part, stubbed out and are not currently live. This will all be live in a future release.

Why use VBA when LISP is so well supported in IntelliCAD?

Speed
To quote Autodesk, "VBA is fast. VBA is hosted by AutoCAD and doesn't have the associated overhead of calling out to a separate process. In internal benchmarks, VBA is significantly faster than AutoLISP or Visual Basic running as a separate application. The execution speed is very close to a compiled C++ ObjectARX DLL-based extension." Programs created with VBA execute faster than programs created outside of an application. For example, a VBA program will run faster than the same code setup as a standalone VB executable (.exe) program.

Ease-of-use
VB/VBA interface is easy to learn and use. VBA-enabled programs (i.e., Word 97, Office 97 Excel 97, AutoCAD 14, Visio Technical, IntelliCAD, etc.) allow the user to learn and program in the same VB environment.

Universality
VBA has become broadly accepted as the Windows-based customization tool of choice. The VBA interface resembles Visual Basic 5 (VB5). IntelliCAD users only need to learn one programming environment (VBA) to be able to program with VB in all VBA enabled programs. The VBA editor included with IntelliCAD uses the same programming environment used in Office 97 applications. LISP only works in a handful of CAD programs.

The VBA interface
With Visual Basic, the programmer creates a user interface by adding controls from the Toolbox to a Form.

The VBA integrated development environment

To create a push button only requires a selection of the button control in the Toolbox and drawing/placing the control on a Form. It is very easy to create a Form that looks the way it will be used as a program. Buttons to push, Text boxes for entry, Option lists, etc., are a breeze to create, size and change. The ability to rapidly create a prototype interface for a new program is stunning to say the least. Also, the resulting Form can be saved and imported into any Windows VBA-enabled program.

How to setup IntelliCAD for VBA
To setup IntelliCAD to run VBA, one needs to have the advanced Tools menu displayed. To get the Advanced Tools menu displayed, do the following:

  • From the pull down menus select Tools > Options
  • In the Options dialog set the Experience level : Advanced
  • From the pull down menu select Tools > Visual Basic (Preview) > Visual Basic Editor or at the command prompt type VBA.
    Loading the VBA (Preview) IDE in IntelliCAD 98
  • Additionally, the Microsoft preferred methodology for launching the VBA environment is by pressing Alt + F11. This is fully supported in IntelliCAD.

After you have done some work on your project it's a very good idea to save your project. IntelliCAD will not prompt you to save changes to a project when closing IntelliCAD. I learned this lesson the hard way. Luckily I only lost about a half of an hour of programming. Save your program/project often and definitely save your project before you exit IntelliCAD!

To load an existing VBA project into IntelliCAD:

Load VBA project

From the pull down menu select Tools > Visual Basic (Preview)… > Load Project or at the command prompt type VBALOAD.

IntelliCAD loads IntelliCAD VBA Project (*.vbi) and/or AutoCAD r14 VBA Project (*.dvb) files (see Figure 3). Also IntelliCAD can load multiple projects for editing at the same time. AutoCAD R14.01 can open only one at a time.

It looks like, again, IntelliCAD understands Multiple Document Interface (MDI) better than Autodesk. Opening multiple drawings in IntelliCAD (MDI) makes editing drawings very productive. Opening multiple Projects for cutting and pasting code between projects makes programming remarkably productive. This is a very welcome innovation in IntelliCAD.

Sample shipping VBI projects (for cutting and pasting code) can be located (using the typical/default IntelliCAD install) at: C:\Program Files\IntelliCAD\Api\Vb\

Describing objects in VBA
VBA uses Objects to work with documents. VBA describes everything within an IntelliCAD drawing (lines, circles, arcs, text, etc.) as an Object. Every Object in a drawing then has properties. A line within the current drawing has a color property that would be described as Thisdocument.lineobj.color. However, most of the VBA in IntelliCAD to describe or modify drawing objects does not work. 

The VBA preview in IntelliCAD did not work as I had hoped or expected; the lack of documentation for the preview VBA in IntelliCAD made it a struggle to create the "rubber stamp" project. I was extremely fortunate to find and use the Mtext object. I had no luck whatsoever in getting the Text object to create text within an IntelliCAD drawing. Possibly, I missed something.

The preview VBA in IntelliCAD for using Forms works wonderfully. The documentation for Forms in the IntelliCAD help-system is extensive and well thought out. Every object (button, textbox, combobox, etc.) on a Form becomes a sub-object of the Form. For example, the TextBox1 on UserForm1 is described as:
UserForm1.TextBox1.

To set the text information in TextBox1 on UserForm1 to display the current drawing name with the path, use the following code:
UserForm1.TextBox1.Text = Thisdocument.path.

Easy! For the curious owners of IntelliCAD, a picture of the IntelliCAD VBA Object model can be found in the file directory C:\Program Files\IntelliCAD\Api\Vb\ IcadObjectModel.jpg.

Frank Zander

Licking your lips for more VBA in IntelliCAD? Then proceed without delay to Part II where Frank Zander shows how to create a working program with VBA.

This article was originally published in Technical Design Solutions
© 1998 ConnectPress Ltd
Re-published by permission

How do you rate this article?
          
Hmmm | OK | Good | Yes! | Brilliant

Copyright © 1998-2001 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home