Divisione Sistemi Informatici - D.S.I.
 

 

Servizi CAD

&

Office Automation

 

Progettazione di sistemi informativi in ambiente AutoCAD(R)

 

INTRODUZIONE ALLA PROGETTAZIONE DI SISTEMI INFORMATIVI CONNESSI CON AUTOCAD (R)

This introduction describes the concept of exposing AutoCAD® objects through an ActiveX® interface and programming those objects using the Visual Basic® for Applications programming environment. Also included is an introduction to all the documentation and sample code provided for AutoCAD ActiveX and VBA.

 

Overview of AutoCAD ActiveX Technology

AutoCAD ActiveX provides a mechanism to manipulate AutoCAD programmatically from within or outside AutoCAD. It does this by exposing AutoCAD objects to the "outside world." Once these objects are exposed, they can be accessed by many different programming languages and environments and by other applications such as Microsoft® Word VBA or Excel VBA.  

 

 

There are two advantages to implementing an ActiveX interface for AutoCAD:

Programmatic access to AutoCAD drawings is opened up to many more programming environments. Before ActiveX Automation, developers were limited to an AutoLISP or C++ interface.

Sharing data with other Windows® applications, such as Microsoft Excel® and Word®, is made dramatically easier.

OVERVIEW OF AUTOCAD ACTIVEX OBJECTS

An object is the main building block of any ActiveX application. Each exposed object represents a precise part of AutoCAD. There are many different types of objects in the AutoCAD ActiveX interface. For example

Graphical objects such as lines, arcs, text, and dimensions are objects

  • Style settings such as linetypes and dimension styles are objects

  • Organizational structures such as layers, groups, and blocks are objects

  • The drawing displays such as view and viewport are objects

  • Even the drawing and the AutoCAD application are considered objects

Overview of AutoCAD Visual Basic for Applications (VBA) Interface

Microsoft VBA is an object-oriented programming environment designed to provide rich development capabilities similar to those of Visual Basic (VB). The main difference between VBA and VB is that VBA runs in the same process space as AutoCAD, providing an AutoCAD-intelligent and very fast programming environment.

VBA also provides application integration with other VBA-enabled applications. Which means AutoCAD, using other application object libraries, can be an Automation controller for other applications such as Microsoft Word or Excel.

The standalone development editions of Visual Basic, which must be purchased separately, complement AutoCAD VBA with additional components, such as an external database engine and report-writing capabilities.

here are four advantages to implementing VBA for AutoCAD:

The Visual Basic programming environment is easy to learn and use.

  • VBA runs in-process with AutoCAD. This translates to very fast program execution.

  • Dialog construction is quick and effective. This allows developers to prototype applications and quickly receive feedback on designs.

  • Projects can be standalone or imbedded in drawings. This choice allows developers great flexibility in the distribution of their applications.

HOW VBA IS IMPLEMENTED IN AUTOCAD

VBA sends messages to AutoCAD by the AutoCAD ActiveX Automation interface. AutoCAD VBA permits the VBA environment to run simultaneously with AutoCAD and provides programmatic control of AutoCAD through the ActiveX Automation interface. This coupling of AutoCAD, ActiveX Automation, and VBA provides an extremely powerful interface not only for manipulating AutoCAD objects, but for sending data to or retrieving data from other applications.

There are three fundamental elements that define ActiveX and VBA programming in AutoCAD. The first is AutoCAD itself, which has a rich set of objects that encapsulates AutoCAD entities, data, and commands. Because AutoCAD was designed as an open-architecture application with multiple levels of interface, familiarity with AutoCAD programmability is highly desirable in order to use VBA effectively. If you've used AutoLISP® to control AutoCAD programmatically, you already have a good understanding of the AutoCAD facilities. However, you will find the VBA object-based approach to be quite different from that of Visual LISP®.

The second element is the AutoCAD ActiveX Automation interface, which establishes messages (communication) with AutoCAD objects. Programming in VBA requires a fundamental understanding of ActiveX Automation. A description of the AutoCAD ActiveX Automation interface can be found in the ActiveX and VBA Reference. Even the experienced VB programmer will find the AutoCAD ActiveX Automation interface invaluable for understanding and developing AutoCAD VBA applications.

The third element is the VBA programming environment which has its own set of objects, keywords, constants, and so forth that provides program flow, control, debugging, and execution. Microsoft's own extensive online help for VBA is included with the AutoCAD VBA and is accessible from the VBA IDE by any of the following methods:

Pressing F1 on the keyboard

  • Choosing Help from the VBA IDE menus

  • Clicking the Question Mark icon on the VBA IDE toolbar

DEPENDENCIES AND RESTRICTIONS WHEN USING AUTOCAD VBA

To ensure the proper functionality of AutoCAD ActiveX and VBA you must comply with the following system dependencies:

Windows NT® 4.0

It is highly recommended that Service Pack 3 for Windows NT 4.0 be installed to run AutoCAD ActiveX and VBA.

Windows® 95, or Windows 98

No special requirements from Microsoft.

Installing, Reinstalling, or Uninstalling Microsoft Office or Other VBA Applications

If you install, reinstall, or uninstall Microsoft Office or other VBA applications after installing AutoCAD, you will need to reinstall AutoCAD. It is highly recommended that after any installation of AutoCAD you reboot your system.

 

Examining the Strengths of AutoCAD ActiveX and VBA Together

The AutoCAD ActiveX/VBA interface represents several advantages over other AutoCAD API environments:

  • Speed - Running in-process with VBA, ActiveX applications are faster than either AutoLISP or ADS applications.

  • Ease of Use - The programming language and development environment are easy to use and come installed with AutoCAD.

  • Windows Interoperability - ActiveX and VBA are designed to be used with other Windows applications and provide an excellent path for communication of information across applications.

  • Rapid Prototyping - The rapid interface development of VBA provides the perfect environment for prototyping applications, even if those applications will eventually be developed in another language.

  • Programmer Base - There are millions of Visual Basic programmers around the world. AutoCAD ActiveX and VBA technology open up AutoCAD customization and application development to these programmers and the many more who will learn Visual Basic in the future.