Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Dermot

Pages: [1]
This was based on request for gettting inforation on Formal-Requirements across into the Test Cases of that object.

This is short piece of Automation Interface code that gives an example of:
- making updates to the repository
- Calling an application using parameters from EA

It needs to be called as an executable from EA.  There are details on the web site for calling an application from EA -

These details would differ for this application:

- The application Name: Requirements
- The command line would be: c:\{YourDir..}\Requirement.exe
- The Arguments would be:  $f, $p

On running EA - open the diagram with the Formal Requirements then select the installed application from the EA menu - Tools | Requirements.  This will give a simple msgbox asking if want to copy the name and notes of each Requirement element in that package.  On selecting 'Yes' it simply copies the Name and Details into a Test Case.

This is simple code.  It only checks if the records already
exist - if so it does not try to add the same name.

Here is the code below:


Option Explicit
Public EARepos As EA.Repository        ' The instance of an EA repository

Private Sub Main()
   'Get the command line parameters, Load the Repository
   'and set some defaults
   Dim Package As EA.Package
   Dim lPackageId As Long
   Dim EafileName As String

   'set what will be parameters in the procudure call
    If Len(Command) > 0 Then                    ' See if there are any arguments.

       ' The Ea repository location             'possible EA Arguments $f, $p
       EafileName = GetParams(Command, 0)
       ' get the package Id
       lPackageId = Val(GetParams(Command, 1))
       'No Arguments may not be running from EA..
       MsgBox ("Please set this up to be called as an application by EA passing the $f, $p arguments.  See:")
   End If
   OpenRepos (EafileName)                   'load up with sepcified path
   Set Package = EARepos.GetPackageByID(lPackageId)
   ScanElements Package
End Sub

Sub ScanElements(Package As Package)
   Dim idx As Integer, oElement As Element, PackageName As String
   ' Scan through each Element - Ask user if they want to add to tests
   For idx = 0 To Package.Elements.Count - 1
       Set oElement = Package.Elements.GetAt(idx)
       ' Check if there are details for this element to be output
        If oElement.Type = "Requirement" Then
           ' if so list the details for the element
           If MsgBox(oElement.Name + "  - Pass to test?", vbYesNo, _
           "Copy to Element Requirements") = vbYes Then
               ElementDetailToTest oElement
           End If
       End If
End Sub

Public Sub ElementDetailToTest(oElement As EA.Element)
    'Copy over the key details for a Requirement Element to Element Requirements
    Dim aTest As EA.Test, idx As Integer
    'Check the test is not already there
    For idx = 0 To oElement.Tests.Count - 1
       If oElement.Tests(idx).Name = oElement.Name Then
           MsgBox ("There is an existing Test of this name")
           Exit Sub
       End If
   ' Create a test case from the Formalrequirements
    Set aTest = oElement.Tests.AddNew(oElement.Name, "Standard")
    aTest.AcceptanceCriteria = oElement.Notes
    aTest.Input = oElement.Notes
End Sub

Public Function GetParams(ParamStr As String, ParamNum As Integer) As String
   Dim words() As String
   words = Split(ParamStr, ",")
   GetParams = words(ParamNum)
End Function

Public Function OpenRepos(EaProjName As String)

   'create the EA Reppository
   Set EARepos = New EA.Repository
   EARepos.OpenFile (EaProjName)                   'load up with sepcified path
   EARepos.ShowWindow (0)                          'optionally hide window

End Function



Automation Interface, Add-Ins and Tools / Working with Connectors
« on: September 28, 2003, 06:19:33 pm »
I have had a some requests from users trying to work out how to deal with outputing details about Connectors in diagrams.

Below is some example code that I have used for doing this.  The call from Main is a simple process for getting at some existing elements in the examle repository for 3.60.


Option Explicit

Public Sub DumpConnections(oElement As EA.Element, Rep As EA.Repository)
   Dim Idx As Integer
   Dim lNumRows As Long, iRows As Integer
   Dim AltObj As EA.Element
   Dim SourceStr As String, TagetStr As String
   Dim Connector As EA.Connector
   ' Set dimensions for the table
   lNumRows = oElement.Connectors.Count
   'Insert the table entries
   For iRows = 1 To lNumRows
          Set Connector = oElement.Connectors.GetAt(iRows - 1)
          ' Check which connector Supplier/Client is the Target/source
          If Connector.ClientID = oElement.ElementID Then
               'Client is the source
               'Set the Alternate Object as the target
               Set AltObj = Rep.GetElementByID(Connector.SupplierID)
               SourceStr = oElement.Name + " " + _
                    IIf(Len(Connector.ClientEnd.Cardinality) > 0, _
                    Connector.ClientEnd.Cardinality + ", ", "") + _
                    IIf(Connector.ClientEnd.Ordering, "Ordered ", "Unordered ")
               TagetStr = AltObj.Name + " " + _
                    IIf(Len(Connector.SupplierEnd.Cardinality) > 0, _
                    Connector.SupplierEnd.Cardinality + ", ", "") + " " + _
                    IIf(Connector.SupplierEnd.Ordering, "Ordered ", "Unordered ")
               'Supplier is the source

               Set AltObj = Rep.GetElementByID(Connector.ClientID)
               SourceStr = AltObj.Name + " " + _
                    IIf(Len(Connector.ClientEnd.Cardinality) > 0, _
                    Connector.ClientEnd.Cardinality + ", ", " ") + _
                    IIf(Connector.ClientEnd.Ordering, "Ordered ", "Unordered ")
               TagetStr = oElement.Name + " " + _
                    IIf(Len(Connector.SupplierEnd.Cardinality) > 0, _
                    Connector.SupplierEnd.Cardinality + ", ", " ") + _
                    IIf(Connector.SupplierEnd.Ordering, "Ordered ", "Unordered ")
           End If
           ' Column 1 - name and type of the connector
           Debug.Print "Connector Type: " + Connector.Type + _
               IIf(Connector.Direction <> "Unassigned ", " ", Connector.Direction)
           'Source object name and ordering
           Debug.Print "Source: " + SourceStr
           Debug.Print "Taget: " + TagetStr
           Debug.Print "Notes: " + Connector.Notes
   Set AltObj = Nothing
   Set Connector = Nothing
End Sub

Sub Main()

   Dim Package As EA.Package
   Dim Diag As EA.Diagram
   Dim Rep As EA.Repository
   Dim aPackageGuid As String
   Dim aProject As EA.Project
   Set Rep = New EA.Repository
   Rep.OpenFile "C:\Program Files\Sparx Systems\EA\EAExample.eap"
   '3.60 example repository
   Set Package = Rep.Models.GetByName("Messenger")
   Set Package = Package.Packages.GetByName("Model Views")
   Set Package = Package.Packages.GetByName("Analysis Model")
   Set Package = Package.Packages.GetByName("Address Book")
   ' display connections for just the first element
   DumpConnections Package.Elements.GetAt(0), Rep
   Set Rep = Nothing
End Sub

The code is written in Vba /VB 6.

If EA version 3.51 is still being used try using:
  'Using EA Version 3.51 ... Different EaExample
   Set Package = rep.Models.GetByName("Views")
   Set Package = Package.Packages.GetByName("Use Case View")
   Set Package = Package.Packages.GetByName("Business Process Model")
   Set Package = Package.Packages.GetByName("Process Model")

to replace the calls to the 3.60 pacakage set above.

Enjoy! :-)

Below is a simple set of code for testing or trying out commands when using the Automation Interface.

It uses the EaExample.eap file.  It is assumed a copy of this is stored in the default installation directory.

The following is some VBA/ VB 6 code for testing the command to generate the HTML report:

Sub Main()
   Dim rep As EA.Repository
   Dim Package As EA.Package
   Dim Diag As EA.Diagram
   Dim aPackageGuid As String
   Dim aProject As EA.Project
   Set rep = New EA.Repository
   'rep.OpenFile "C:\temp\EAExample.eap"
   rep.OpenFile "C:\Program Files\Sparx Systems\EA\EAExample.eap"
   'Using EA Version 3.51 ... Different EaExample
'   Set Package = rep.Models.GetByName("Views")
'   Set Package = Package.Packages.GetByName("Use Case View")
'   Set Package = Package.Packages.GetByName("Business Process Model")
'   Set Package = Package.Packages.GetByName("Process Model")
   'Using v3.60...EAexample
   Set Package = rep.Models.GetByName("Messenger")
   Set Package = Package.Packages.GetByName("Model Views")
   Set Package = Package.Packages.GetByName("Business Context Model")
   Set Package = Package.Packages.GetByName("Business Requirements Model")
   aPackageGuid = Package.PackageGUID
   'Place to test some commands..
   Set aProject = rep.GetProjectInterface()
   aProject.RunHTMLReport aPackageGuid, "C:\temp", "BMP", "", "htm"
   ' end test..
   Set rep = Nothing
End Sub

Please refer to for references on using the Automation Interface.

Automation Interface, Add-Ins and Tools / Automation Interface background
« on: September 26, 2003, 12:33:09 am »
This is just to give some background information about the Automation Interface :

On the website there is a new set of pages with some example code/application for using the Automation Interface.  This is available from:

There is a set of documentation defining the use of the Automation Interface available in the Enterprise Architect Helpfiles which can be found under the Help | Help Contents | Automation and Scripting menu item in EA.

There is reference to this in HTML format in EA under Help | Online Resources | Automation Interface - this takes you to the online version (The direct address to this:

Pages: [1]