CADinfo.net

CAD, CAM, CAE, design, technical drawing, drafting, delineation, visualization, manufacturing

  • Full Screen
  • Wide Screen
  • Narrow Screen
  • Increase font size
  • Default font size
  • Decrease font size
advertisement

Visual Basic for Applications in IntelliCAD

Article Index
Visual Basic for Applications in IntelliCAD
Part 2
Page 3
Page 4
All Pages

A series of articles introducing custom programming of IntelliCAD and AutoCAD using Visual Basic for Applications (VBA).

advertisement

This article introduces you to VBA, how it is installed in IntelliCAD and how to add a VBA routine to a menu.  While this may leave VBA as mysterious as ever for some readers, the fog should begin to clear as the series progresses.

Visual Basic for Applications (VBA) is a programming language which can be 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.

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 LISP 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 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 and the need to obey specific requirements when interfacing your application to the host CAD program.

The VBA Editor screen in IntelliCADVBA 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 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.

The next question to be addressed is, how do we access VBA in IntelliCAD?  We first have to install it.  My advice here will relate directly to the IntelliCAD Professional 2000 by CADopia, though other versions should be very similar.  CADopia only provides VBA support in their "Professional" version, so this wont work if you're using the "Standard" version of the program.  I've also not yet determined if their recently release 2001 version has any fundamental changes to it, though I doubt this would be the case.

The biggest problem with installing VBA is that the procedure is not very well documented anywhere.  Once you know how, it's quite simple.  Installation has to be done manually, after the IntelliCAD program itself has been installed.  So one must first install IntelliCAD, if this hasn't already been done.  Then, take a look at the sub-directories under the main IntelliCAD root directory.  You should find a sub-directory named "RELEASE".  In this will be a file named "VBA6.MSI". This is the VBA installation program.

What you do next will depend on how the copy of Windows on your particular computer has been set up, and on what programs it may have run in the past.

My recommendation is to do the following.  First, start the Windows File Manager.  Then find the "VBA6.MSI" file in the "RELEASE" sub-directory and double-click on it.  This should cause Windows to run the file, or to give you an error message advising it doesn't know what application to use with this file.  If the file runs, then that's great because you have just successfully installed VBA and don't have to worry about anything in the following paragraph.

If you get the error message then it will be necessary to run another program first, then to run the "VBA6.MSI" file.  You will now need to check in the "MSI" sub-directory below the "RELEASE" sub-directory.  This should contain two program files, named INSTMSI.EXE and INSTMSIW.EXE. You will need to run the first file if you're using Windows 98 (or similar), and the second file if you're using Windows NT (or similar).  Run the program by double-clicking on the file name in the Windows File manager.  Not much visible should happen when the program runs.  Then, return to the "VBA6.MSI" file and double-click on it again.  This time it should run and VBA will be installed.

Finally, reboot your computer.  This final step may not be necessary but it's easier to do it than not, if only for peace of mind.  We have now installed VBA for IntelliCAD.

There is one final step to perform.  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 from about midway down the TOOLS pulldown.

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.

In short, you use VBA to get the Editor up for programming, and use VBARUN to cause the program to execute.  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 I 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;

The 'Run Macro' screen in IntelliCADWhen 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 more articles in this series where we will introduce the use of Visual Basic for Applications and how it can be applied to perform practical operations within IntelliCAD.



 

Add comment


Security code
Refresh

 

 

 

We are pleased to offer you this exciting, new, and entirely free professional resource. Visit our Free Industry resource center today to browse our selection of 600+ complimentary Industry magazine subscriptions. Get popular titles including:

Oil, Gas & Petrochem Equipment
Underground Construction
Equipment World

No credit cards, coupons, or promo codes required. Try it today!