Automation Interface Examples: Code Details
- Description of code
- Setting up MS VB to use EA's Automation interface
- Basic concepts
- EA is installed on the machine
- Microsoft Word 2000 or later is installed on the machine
- Visual Basic 6.0 is installed on the machine if you wish to develop the application
The code details provide additional information to the documentation on the use of the Automation Interface. The intention is to provide an example on using Visual Basic to perform calls to the Automation Interface to retrieve data from an EA repository. This code is considered as a starter for users to configure their own documentation layouts.
It is assumed there would be a reasonable knowledge of Visual Basic if modifications are to be made to the following example. Guidelines on the Use of the Automation Interface have been provided with EA (see References).
Description of Code
The code for AutInt is a Visual Basic 6.0 .dll written to interface with Enterprise Architect. Apart from the main-form and the class, all the other code is able to be transported to any VBA environment such as MS-Word etc.
The AutInt.dll application is loaded when EA starts. It is referenced in the registry under two settings
a) The DLL entry
b) The EA Add-In entry which references the DLL entry. (for more information on this see Calling Applications from EA).
The basic concept behind the code is that it runs through the hierarchy of an EA repository from the Model level and calls Word functions to add the data to the document. The key starting points for running through the EA repository are the DumpModel and DumpPackage routines.
The DumpModel routine runs through the set of project trees (packages) calling the recursive function DumpPackage. Each diagram and the set of Elements/Packages are processed under this.
When calling the code from EA, and a PackageID is passed across, the routine DumpPackage is called directly and passed the PackageID.
The Call Cycle is as follows:
'Closes the open files
' Opens the EA Application and Word Application and calls the following..
' Creates the document
' Parses the Model
' Parses the Packages
' Parses the Diagrams in the package
' Parses the Elements in the package
' Creates a table of Connections
' Creates a table of Attributes
' Creates a table of Methods
' Get Word to create the Contents
' Sets up the Introduction pre the Contents
Setting up MS VB to use EA's Automation interface
To set up the Viusaul Basic 6 project to generate the DLL - create the new project in VB as an 'ActiveX DLL'. See in EA's help file under 'Automation and scripting' - 'Creating addins' for a full description of setting up the class structure. Once the initial Dll has been created see Calling EA Addin for a decription of setting the registry reference to the DLL.
The following is a brief description of the contents of each of the modules within AutInt. This code is Downloadable.
|frmWordReport||The main form used for selection of options and defining file locations etc.|
|Repository.bas||Main code for generating the standard EA Document in Word.|
|DetailDocs.bas||Detail runs of Testing and Maintenance (Similar to Repository.bas)|
|Document.bas||A set of routines for manipulating VB-Word.|
|UseCase.bas||Code for generating the Use Case Document.|
|EaAddin.cls||The EA Add-Ins class|
A brief description of some of the Public Variables defined in the application:
|WordApp||The Word Application|
|EADoc||The word Document|
|EaRepos||The instance of the current EA repository|
Some Notes about Word
1) Spelling and Grammar Checking
With the CreateDocument code, spelling and grammar checking in Word have been set off to improve efficiency. If spelling or grammar checking is required, it is best to run them as a secondary event to ensure the CPU usage is within reasonable bounds. The process time is proportionally greater for Word.
An error was encountered when inserting numerous "header 1" headers. Inserting these regularly causes problems see ref: 293087 Word 97 bug report. A solution is to save and update the file regularly to fix the problem. See: http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B293087