Book a Demo

Author Topic: Import element relationships  (Read 6379 times)

ilopez

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Import element relationships
« on: September 05, 2018, 06:40:06 am »
I have a model in Enterprise Architect and I need to import some relationships (of already existing elements) that I have in an Excel. I tried running a JScript but wasn't able to run it (haven't still figured out why).

How can I import a massive amount of relationship into my model?

Thanks in advance.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Import element relationships
« Reply #1 on: September 05, 2018, 06:53:52 am »
Well, you probably need to write a program (script or whatever) to do the magic. Somehow you need to match the elements in EA and from your Excel source (probably by name, better by some GUID) and then you can create relations.

q.

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: Import element relationships
« Reply #2 on: September 05, 2018, 11:57:01 am »
Hi Ilopez, you can import in the relationships using this script in Excel:

Sub relationshipcreate(outputws As Worksheet)
    Dim x As Integer
    x = 3
    Do Until IsEmpty(outputws.Cells(x, 4))
        If IsEmpty(outputws.Cells(x, 4)) Or IsEmpty(outputws.Cells(x, 8)) Or IsEmpty(outputws.Cells(x, 9)) Then
            MsgBox "The relationships have not been populated correctly in row " & x & vbCrLf & vbCrLf & "Please check the " & outputws & " tab" & _
            vbCrLf & vbCrLf & x - 3 & " relationships have been created in EA", vbOKOnly
            Exit Sub
        Else
            Call addConnector(outputws.Cells(x, 4), outputws.Cells(x, 8), outputws.Cells(x, 9), outputws.Cells(x, 10))
            x = x + 1
        End If
    Loop
    MsgBox x - 3 & " relationships have been created in EA", vbOKOnly
    outputws.Select
    outputws.Cells.EntireColumn.AutoFit
    outputws.Cells(3, 1).Select
End Sub


Function addConnector(SourceElementID, TargetElementID, ConnectorType, connectorname)
Dim SourceElement As EA.element
Dim newconnector As EA.connector
    Dim repository As EA.repository
    Set eaapp = GetObject(, "EA.App")
Set repository = eaapp.repository
Set SourceElement = repository.GetElementByID(SourceElementID)

Set newconnector = SourceElement.connectors.AddNew(" ", ConnectorType)

newconnector.SupplierID = TargetElementID
newconnector.Name = connectorname
newconnector.Update
Set addConnector = newconnector
End Function



The excel worksheet columns will need to be in this format:

SourcePackage,SourceType,SourceName,SourceID,TargetPackage,TargetType,TargetName,TargetID,RelationshipType,RelationshipName


You will first have to retrieve the ID's of the elements from the model. Let me know if you need a hand getting these.

Cheers,
Rupert

ilopez

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Import element relationships
« Reply #3 on: September 07, 2018, 02:15:52 am »
Thanks a lot @rupertkiwi. I stil have doubts, can you help me please?

-I'm currently using version 13.5.1351
-I'm using the corporate edition
-Do I need some kind of add-in to run use this excel?
-How do I declare what model should be used?

I'm very newby with EA. Thanks for your help and your patience.

Isaac.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Import element relationships
« Reply #4 on: September 07, 2018, 04:39:25 am »
I'm not a VB guy but it looks as if that script runs in Excel and accesses EA (the currently running one).

q.

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: Import element relationships
« Reply #5 on: September 07, 2018, 10:37:05 am »
Hi Isaac,

In response to your questions:


-I'm currently using version 13.5.1351
I'm running v13 too

-I'm using the corporate edition
Me too

-Do I need some kind of add-in to run use this excel?
Yes. You need to add a reference to the 'Enterprise Architect Object Model 2.10' in the VBA editor for Excel. You do this by selecting TOOLS --> REFERENCES in the VBA editor for Excel. This is also where you will paste the code.

-How do I declare what model should be used?
It will run on the model that you currently have open. You will also need to retrieve the ID's of the elements that you want to create the relationships for from the model that you have open. I will find some code for this and send it to you.

Cheers,
Rupert

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: Import element relationships
« Reply #6 on: September 07, 2018, 11:27:19 am »
Hi Isaac,

This will retrieve the element ID's that you want to create the relationships for:

Sub RecursiveModelDumpExample()
    Dim outputws As Worksheet
    Set outputws = Worksheets("Sheet1")
    outputws.Rows("2:" & Rows.Count).ClearContents
    Dim repository As EA.repository
    Set eaapp = GetObject(, "EA.App")
    Set repository = eaapp.repository
    Dim thePackage As EA.Package
    Set thePackage = repository.GetTreeSelectedPackage()
    If Not thePackage Is Nothing And thePackage.ParentID <> 0 Then
    Dim j As Integer
    j = 2
    Dim currentElement As EA.element
    For Each currentElement In thePackage.elements
            outputws.Cells(j, 1) = thePackage.Name
            outputws.Cells(j, 2) = currentElement.Name
            outputws.Cells(j, 3) = currentElement.MetaType
            outputws.Cells(j, 4) = currentElement.elementid
            outputws.Cells(j, 5) = currentElement.Stereotype
            j = j + 1
    Next
    Else
        ' No package selected in the tree
        MsgBox ("This script requires a package to be selected in the Project Browser." & vbCrLf & _
            "Please select a package in the Project Browser and try again.")
    End If
End Sub

Just select a package first in EA.

Cheers,
Rupert