Author Topic: Inserting Archimate Connectors with Scripting - I must be missing something!  (Read 8307 times)

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
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...



But, instead, I see this....



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? 
Rich Anderson
Urgnt Limited

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
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()

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Looking in the Archimate 2 MDG I see

Code: [Select]
<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.

Rich Anderson

  • EA User
  • **
  • Posts: 142
  • Karma: +8/-0
    • View Profile
    • LinkedIn
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()
Rich Anderson
Urgnt Limited

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
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

Geert

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
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.  Or are you speaking in a UML 2.x sense?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
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
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
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 :-)