Hello everyone,
This is my first post on this forum. I'm using Enterprise Architect for a little while now and I'm focussing on generating a datamodel from Excel.
At first I tried using "eaexcelimporter_v4.xls" but it did not work for me. The company I work at has some strict network policies and makes importing from Excel to EA impossible. So I started a VBscript in EA and now it reads the Excel.
So far I learned how to create an element with properties, attributes with properties, tagged values and creating connections. Now I have one challenged left, multiplicities.
I have really learned a lot from the local scripts and the excel from Geert Bellekens. But I can't find anything on the internet about adding multiplicities.
It reads the information from an Excel with the following layout:
A | B | C | D | E | F | G | H |
1 | Source_Name | Source_ID | Target_Name | Target_ID | Tagged_Value | Source_Multiplicity | Target_Multiplicity |
2 | Chair | 12975 | Desk | 12945 | P1 | 1 | 0..* |
3 | Computer | 12954 | Desk | 12945 | P2 | 1..* | 0..* |
It creates an connection with the Source_ID and Target_ID. It also adds a TaggedValue. I want it to add the multiplicity too, but I can't figure out the proper code to do this. I tried many ways, but my work comes to a stand still. I added my code with this post. It's no clean code and has no error handling, but that comes later, after I get used again to VBscript.
I hope someone can help me to add the multiplicity in VBscript.
sub Relations
Repository.EnsureOutputVisible "Script"
dim Package as EA.Package
set Package = Repository.GetTreeSelectedPackage()
if not Package is nothing and Package.ParentID <> 0 then
dim objExcel
dim objWorkbook
dim objWorksheet
dim path
dim file
path = "D:\Modellen\Importbestanden\"
file = "Relationship_Matrix_Input.xlsx"
set objExcel = CreateObject("Excel.Application")
set objWorkbook = objExcel.Workbooks.Open(path & file)
set objWorksheet = objWorkbook.Worksheets("Relations")
dim Object_sourceID as EA.Element
dim Object_targetID as EA.Element
dim Object_source as EA.Element
dim AddRelation as EA.Connector
dim Line
dim Check
Check = ""
Line = 2
Session.Output( "Relations from Excel" )
Session.Output( "====================================" )
dim tags as EA.Collection
dim newTag as EA.AttributeTag
' ----------------------------------
Do Until objWorksheet.Cells(Line,1).Value = ""
If Check <> objWorksheet.Cells(Line, 1).Value Then
Object_sourceID = objWorksheet.Cells(Line, 3).Value
Object_targetID = objWorksheet.Cells(Line, 5).Value
set Object_source = Repository.GetElementByID(Object_sourceID)
set AddRelation = Object_source.Connectors.AddNew("", "Association")
AddRelation.SupplierID = Object_targetID
AddRelation.Update
' TAGS aan en uit zetten
' ----------------------------------------------------------------------------
set tags = AddRelation.TaggedValues
set newTag = tags.AddNew( "Tag Matrix", objWorksheet.Cells(Line, 6).Value )
newTag.Update()
tags.Refresh()
Check = objWorksheet.Cells(Line, 1).Value
Session.Output( objWorksheet.Cells(Line, 2).Value & " AddRelation met " & objWorksheet.Cells(Line, 4).Value & " with priority " & objWorksheet.Cells(Line, 6).Value & ".")
set Object_sourceID = nothing
set Object_targetID = nothing
set Object_source = nothing
set AddRelation = nothing
set tags = nothing
set newTag = nothing
End If
Line = Line + 1
Loop
Session.Output( "====================================" )
Session.Output( "AddRelations verwerkt" )
objExcel.Quit
else
MsgBox( "No package found" & vbCrLf & _
"Select a package and try again." )
end if
end sub
Relations