Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Rich Anderson on February 24, 2016, 04:45:18 pm
-
Hi There, I am relatively new to scripting, having read and applied the "Scripting Enterprise Architect" book and getting to work pretty well so far. I am working on building a model in Archimate where I'm importing elements and need to generate connections with the script. I'm using Visual Studio with VB for the scripting and that is working well for me. So, here is a bit of simple code that should generates a sample connection:
Dim element1 As Element
Dim element2 As Element
Dim newconnector As Connector
element1 = SparxEARepository.GetElementByGuid("{51D3256F-2B89-4299-9B32-9A9032C3C877}")
element2 = SparxEARepository.GetElementByGuid("{30AE709D-58CB-4bfb-A9DF-B412A650F521}")
newconnector = element1.Connectors.AddNew("", "Assignment")
newconnector.SupplierID = element2.ElementID
newconnector.Stereotype = "ArchiMate_Assignment"
newconnector.Direction = "Unspecified"
newconnector.Update()
element1.Connectors.Refresh()
element2.Connectors.Refresh()
So, when I include this connector on a diagram, I was expecting/hoping to see this...
(http://s17.postimg.org/yoxmnoybz/hope.png)
But, instead, I see this....
(http://s27.postimg.org/9yfhnohpv/reality.png)
When I look at the properties for the connector, I cannot see any obvious problem, so I can only assume from this that at there are other attributes that need to be set that I'm not setting! I've searched around quite a bit and cannot seem to find any decent way to figure this out.
So, can anyone here shed any light on this or point me in the right direction?
-
The problem is the connector type you are using when creating the connector
You have to use the same underlying connector type as the regular Archimate assignment connectors.
"Assigment" is not a valid connector type.
You can verify the connector type in the database. Probably "Association".
Geert
PS. And you probably don't need the calls to Refresh()
-
Looking in the Archimate 2 MDG I see
<Tag name="Archimate2::Archimate_Composition(UML::Composition)" type="" description="" unit="" values="" default="Composition"/>
<Tag name="Archimate2::Archimate_Aggregation" type="" description="" unit="" values="" default="Aggregation"/>
<Tag name="Archimate2::Archimate_Assignment" type="" description="" unit="" values="" default="Assignment"/>
<Tag name="Archimate2::Archimate_Realization" type="" description="" unit="" values="" default="Realization"/>
<Tag name="Archimate2::Archimate_UsedBy" type="" description="" unit="" values="" default="Used By"/>
<Tag name="Archimate2::Archimate_Access" type="" description="" unit="" values="" default="Access"/>
<Tag name="Archimate2::Archimate_Association" type="" description="" unit="" values="" default="Association"/>
<Tag name="Archimate2::Archimate_Triggering" type="" description="" unit="" values="" default="Triggering"/>
<Tag name="Archimate2::Archimate_Flow" type="" description="" unit="" values="" default="Flow"/>
<Tag name="Archimate2::Archimate_Grouping" type="" description="" unit="" values="" default="Grouping"/>
<Tag name="Archimate2::Archimate_Junction" type="" description="" unit="" values="" default="Junction"/>
<Tag name="Archimate2::Archimate_Specialization" type="" description="" unit="" values="" default="Specialization"/>
So I'd say everything but Archimate Composition is actually an association as Geert suggested.
-
Thanks! That was a big help. I also managed to get it to generate a composition connector equivalent to drawing by hand. Here is the new code...
'ADDS AN ASSIGNMENT CONNECTOR
Dim element1 As Element
Dim element2 As Element
Dim newconnector As Connector
element1 = SparxEARepository.GetElementByGuid("{51D3256F-2B89-4299-9B32-9A9032C3C877}")
element2 = SparxEARepository.GetElementByGuid("{30AE709D-58CB-4bfb-A9DF-B412A650F521}")
newconnector = element1.Connectors.AddNew("", "Association")
newconnector.SupplierID = element2.ElementID
newconnector.Stereotype = "ArchiMate_Assignment"
newconnector.Direction = "Unspecified"
newconnector.Update()
'ADDS A COMPOSITION CONNECTOR (Thanks, Glassboy!)
Dim element3 As Element
Dim newcomp As Connector
element3 = SparxEARepository.GetElementByGuid("{79F0F589-319D-4c35-BD73-B5E1CBC89F0E}")
newcomp = element3.Connectors.AddNew("", "Composition")
newcomp.SupplierID = element2.ElementID
newcomp.Stereotype = "ArchiMate_Composition"
newcomp.Direction = "Source -> Destination"
newcomp.SupplierEnd.Aggregation = 2
newcomp.Update()
-
I don't think "Composition" is a valid connector type either.
Not sure why it works anyway (maybe EA translates it behind the covers), but the connector type used by EA is "Aggregation"
You can find a list of connector types in the help http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/connector2_2.html (http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/connector2_2.html)
Geert
-
I don't think "Composition" is a valid connector type either.
It's in the list http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/connectors_used_in_toolboxes.html (http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/connectors_used_in_toolboxes.html). Or are you speaking in a UML 2.x sense?
-
I think the Composition in the MDG list is an <extension> of Aggregation in the canonical list of types referenced by Geert. (see second bullet on the referenced page)
As may be known, a composition is stored in t_connector as Type=Aggregation Subtype=Strong - the "extension of Aggregation".
Consequently, in order to make it easier for users, the API will translate as Geert suggested a type of Composition to Strong Aggregation.
HTH,
Paolo
-
As may be known, a composition is stored in t_connector as Type=Aggregation Subtype=Strong - the "extension of Aggregation".
Consequently, in order to make it easier for users, the API will translate as Geert suggested a type of Composition to Strong Aggregation.
There are those people who think (and to paraphrase Mr T.)that aggregation is for fools :-)