Book a Demo

Author Topic: Importing relationships from Excel  (Read 8825 times)

PhilBennett1

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Importing relationships from Excel
« on: May 13, 2015, 01:08:10 pm »
Hi,

It seems to be a hot topic and I have found various pieces of the puzzle of importing relationships from Excel however does anyone actually have the code used to do so that I could please have?

I have a script working that will update the t_connector table with new rows however advice from various people (including Geerts) is to not do it that way. Unfortunately then I hit the wall of my technical capabilities and have been unable to create a whole script that will import my relationships.

Thanks in advance!

smendonc

  • EA User
  • **
  • Posts: 148
  • Karma: +5/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Importing relationships from Excel
« Reply #1 on: May 13, 2015, 03:16:52 pm »
There is a complete script to create a relationship (connector) in the help at /Automation and Scripting/Enterprise Architect Object Model/Reference/Code Samples/Add a Connector.  

The MDG Office Integration that Sparx just released will allow you to do this as will EADocx.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Importing relationships from Excel
« Reply #2 on: May 13, 2015, 03:46:31 pm »
Adding a relation to an element using the API is actually quite simple.

You need

- SourceElement as EA.Element
- TargetElementID as Long
- ConnectorType as String

Then you do can call a method like this one:
Code: [Select]
function addConnector (SourceElement, TargetElementID,ConnectorType)
      dim NewConnector as EA.Connector
      'Create the new connector at the source element
      set NewConnector = SourceElement.Connectors.AddNew("name or empty string", ConnectorType)
      'Set the target element
      NewConnector.SupplierID = TargetElementID
      'Save the connector
      NewConnector.Update
      'Return the connector
      set addConnector = NewConnector
end function

Geert
« Last Edit: May 13, 2015, 03:46:53 pm by Geert.Bellekens »

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Importing relationships from Excel
« Reply #3 on: May 13, 2015, 05:27:36 pm »
For completeness eaDocX can also import relationships as well as elements and any required fields from Excel.
Go to EaDocX.com for a trial version which gives you 30days to check out if it does what you want!
« Last Edit: May 13, 2015, 11:06:00 pm by MrWappy »
EXploringEA - information, utilities and addins

EA_geek

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Importing relationships from Excel
« Reply #4 on: May 13, 2015, 09:47:45 pm »
Hi PhilBennett1,

Try MDG Office Integration from Sparx Systems to import data from excel which will allow to import relationships and elements also set stereotypes to the elements

download MDG office integration from the below link: http://sparxsystems.com/products/mdg/int/office/office-integration.html

i hope this will simplify your task  :)

Thanks,
Nabil

Sam Courtney

  • EA User
  • **
  • Posts: 58
  • Karma: +1/-0
    • View Profile
Re: Importing relationships from Excel
« Reply #5 on: May 13, 2015, 10:22:36 pm »
We provide a platform that will handle relationship importing for data from target sources - see this link:
http://www.aprocessgroup.com/products/apg-modelflow/

PhilBennett1

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Importing relationships from Excel
« Reply #6 on: May 14, 2015, 09:45:54 am »
Thank you all.

I managed to get the following code to work based on Geerts example.
Code: [Select]
function addConnector(SourceElementID,TargetElementID,ConnectorType)

      dim SourceElement
      dim NewConnector as EA.Connector
      Set SourceElement = Repository.GetElementByID(SourceElementID)
      
      'Create the new connector at the source element
      set NewConnector = SourceElement.Connectors.AddNew(" ", ConnectorType)
      
      'Set the target element
      NewConnector.SupplierID = TargetElementID
      'Extra fields below if need be
      'NewConnector.Stereotype = "RequirementRelated"
      'NewConnector.Direction = "Source -> Destination"
      'Save the connector
      NewConnector.Update
      'Return the connector
      set addConnector = NewConnector
end function

'this is our main function, that we will call the function with the required fields
Sub Main
    Call addConnector(49201,49203,"Realization")
End Sub