Author Topic: Working with Connectors  (Read 1090 times)

Dermot

  • EA Administrator
  • EA User
  • *****
  • Posts: 583
  • Karma: +6/-0
    • View Profile
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 ")
           Else
               '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
   
   Next
   
   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
   
   Rep.Exit
   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! :-)