Hi guys,
i have been working with Enterprise Architect for 2 months and my objective is, from a Excel file, generate a diagram within the relations between the elements(mainly "InformationFlow", "Derive","Usage"). In order to achieve this, i use the MDG Integration Office Add-in and i could do it, but i need to do the process in an automatic way: Run a script inside EA should be enough. I have developed a code in VBScript but it is not working - in fact, i can run the script but anything happens/changes in the software. Can you help me with the code or suggest any other way to achieve my objective? Unfortunately i only have 2 months to finish this project... Here i let the code that was written in the scripting Window of my Enterprise Architect.
option explicit
!INC Local Scripts.EAConstants-VBScript
'
' Script Name: import excel into EA
' Author: Andre
' Purpose: import an excel file in order to generate a diagram and its elements
' Date: 19/06/2023
'
Sub importexcel()
' Set the path and filename of the Excel file to import
Dim filePath
Dim fileName
filePath = "MyPathtomyFile"
fileName = "my_file.xlsx"
' Set the name of the package to import the data into
Dim packageName
packageName = "New Package"
' Set the name of the object profile and connector profile to use
Dim objProfileName
Dim conProfileName
objProfileName = "my_objprofile_name"
conProfileName = "my_conprofile_name"
' Import the data from the Excel file
Dim repository As EA.Repository
Set repository = GetObject("MyPathtomyFile", "EA.App").Repository
repository.ImportCSVEx filePath & fileName, objProfileName, conProfileName, packageName, False, False, False, False, False, False
' Create a new diagram to represent the imported data
Dim diagram As EA.Diagram
Set diagram = repository.Diagrams.AddNew("name_of_diagram", "ActivityDiagram")
diagram.PackageID = repository.GetPackageByGuid(repository.Models.GetAt(0).PackageGUID).PackageID
diagram.Update
' Find the objects that were imported and add them to the diagram
Dim objects As EA.Collection
Set objects = repository.GetElementsByQuery("SELECT Object_ID FROM t_object WHERE Stereotype = 'YourStereotypeName' AND Package_ID = " & repository.GetPackageByName(packageName).PackageID)
Dim obj As EA.Element
For Each obj In objects
Dim diagramObject As EA.DiagramObject
Set diagramObject = diagram.DiagramObjects.AddNew("", "")
diagramObject.ElementID = obj.ElementID
diagramObject.Update
Next
' Find the connectors that were imported and add them to the diagram
Dim connectors As EA.Collection
Set connectors = repository.GetElementsByQuery("SELECT Connector_ID FROM t_connector WHERE Package_ID = " & repository.GetPackageByName(packageName).PackageID)
Dim con As EA.Connector
For Each con In connectors
Dim diagramLink As EA.DiagramLink
Set diagramLink = diagram.DiagramLinks.AddNew("", "")
diagramLink.ConnectorID = con.ConnectorID
diagramLink.Update
Next
' Refresh the view to show the imported data and the new diagram
repository.RefreshModelView (packageName)
End Sub