Author Topic: Adding Conveyed Items to a connector  (Read 4936 times)

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Adding Conveyed Items to a connector
« on: July 29, 2024, 07:45:55 pm »
I am using a VB script to create a connector by
Code: [Select]
Dim newConnector As EA.Connector
Set newConnector = ...Connectors.AddNew("", "Association")
newConnector.SupplierID = ...ElementID

I now want to add a conveyed item by
Code: [Select]
newConnector.ConveyedItems.AddNew InformationFlow , ""

The problem I have is: I do not see that in the diagram. And I also do not see the informationFlow being added in the t_xref database.

What I expected:
Manually, when I add a connector between two ports, then rightclick on it and use "Advanced" -> "Information Flows realized..." it will show the connector and the information flow that I put on it. It will in the database create a connector in the t_connector and a reference of the conveyed flow in the t_xref.
I want to mimic that behaviour by VB script and I am failing to find out, what to do to do the t_xref part.
Is the best option here an SQL insert query? (if yes, any idea how to create a GUID and check if it is not used already (I know probabilty is quite really low, but still).

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #1 on: July 29, 2024, 07:59:28 pm »
You didn't RTFM I guess ;D

https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/connector2_2.html

Here's the relevant part:
Quote
To add another element to the conveyed Collection, use 'AddNew (ElementGUID,NULL)', where 'ElementGUID' is the GUID of the element to be added.

The ConveyedItems collection is a bit different from other collections.

Geert

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #2 on: July 29, 2024, 08:12:35 pm »
I thought that's what I tried by using
Code: [Select]
newConnector.ConveyedItems.AddNew InformationFlow , ""
I also tried
Code: [Select]
newConnector.ConveyedItems.AddNew "{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , NULLwhich shows a type conflict
or
Code: [Select]
newConnector.ConveyedItems.AddNew("{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , "")which shows not using () in case of sub routines
or
Code: [Select]
newConnector.ConveyedItems.AddNew "{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , ""which just does nothing
with {16B42F4C-8038-495c-B5B4-73C8C76F1B43} being the GUID of a block I want to use as the information flow.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #3 on: July 29, 2024, 08:51:56 pm »
Did you Update() the connector before trying to add a conveyed item?

If it then still doesn't work you could try:

Code: [Select]
dim conveyed
set conveyed = newConnector.ConveyedItems.AddNew("{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , "")
conveyed.Update

But I think it's more likely to be the lack newConnector.Update()

Geert

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #4 on: July 29, 2024, 08:59:06 pm »
Did you Update() the connector before trying to add a conveyed item?

If it then still doesn't work you could try:

Code: [Select]
dim conveyed
set conveyed = newConnector.ConveyedItems.AddNew("{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , "")
conveyed.Update

But I think it's more likely to be the lack newConnector.Update()

Geert

I did not think about the newConnector.Update() BEFORE adding the conveyed item. However, that does not change anything.

For the:
Code: [Select]
dim conveyed
set conveyed = newConnector.ConveyedItems.AddNew("{16B42F4C-8038-495c-B5B4-73C8C76F1B43}" , "")
conveyed.Update

This throws an error on the last line (conveyed.Update) saying an object is missing. For me, it seems like it is not added and therefore there is no object. Completely lost on why to be honest.

To give you exact info:
The {16B42F4C-8038-495c-B5B4-73C8C76F1B43} is the GUID of an <<interfaceBlock>> that has on it a <<flowProperty>>
« Last Edit: July 29, 2024, 09:00:45 pm by ScriptUser »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #5 on: July 29, 2024, 09:50:52 pm »
This code works

Code: [Select]
dim sourceClass as EA.Element
set sourceClass = Repository.GetElementByGuid("{EDFA7390-50D6-4987-9905-DB1122341F6C}")
dim targetClass as EA.Element
set targetClass = Repository.GetElementByGuid("{3ABFB810-1613-4f82-B74A-CCF3F8526B01}")
dim conveyedClass as EA.Element
set conveyedClass = Repository.GetElementByGuid("{579CBCCE-354E-482e-B23A-1B9EF0EB5876}")
dim connector as EA.Connector
set connector = sourceClass.Connectors.AddNew("new flow", "InformationFlow")
connector.SupplierID = targetClass.ElementID
connector.Update
'add conveyed item
connector.ConveyedItems.AddNew conveyedClass.ElementGUID, ""
'reload
Repository.ReloadPackage sourceClass.PackageID

There is something special if you want to add conveyed items to something different then an informationflow (like an association in your case). In that case EA generates an "hidden" informationflow that is then linked to your association.
I think you'll need to replicate that if you really need the connector to be an association.

Geert

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #6 on: July 29, 2024, 11:01:46 pm »
This code works

Code: [Select]
dim sourceClass as EA.Element
set sourceClass = Repository.GetElementByGuid("{EDFA7390-50D6-4987-9905-DB1122341F6C}")
dim targetClass as EA.Element
set targetClass = Repository.GetElementByGuid("{3ABFB810-1613-4f82-B74A-CCF3F8526B01}")
dim conveyedClass as EA.Element
set conveyedClass = Repository.GetElementByGuid("{579CBCCE-354E-482e-B23A-1B9EF0EB5876}")
dim connector as EA.Connector
set connector = sourceClass.Connectors.AddNew("new flow", "InformationFlow")
connector.SupplierID = targetClass.ElementID
connector.Update
'add conveyed item
connector.ConveyedItems.AddNew conveyedClass.ElementGUID, ""
'reload
Repository.ReloadPackage sourceClass.PackageID

There is something special if you want to add conveyed items to something different then an informationflow (like an association in your case). In that case EA generates an "hidden" informationflow that is then linked to your association.
I think you'll need to replicate that if you really need the connector to be an association.

Geert

Ok, as you said, your code works for an informationFlow with an information Flow realized conveyed to it.

Just that "hidden" informationflow is something I have read already multiple times, but no one seems to neither get it to work or at least describe how he got it to work.
Really complicated implementation it seems...

Thanks already for your input!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #7 on: July 29, 2024, 11:15:33 pm »
It's not really that complicated.

You need to make an informationflow (like in the code I shared) and then link it to the association.
The link between the association and the informationflow is made in the t_xref of the association.

This is the code that gets the id's of the other connectors when starting from the information flow.
Code: [Select]
// because access doesn't want to join on the description field (memo) we cannot use proper SQL join syntax
string sqlGetRealization = @"select crel.Connector_ID from t_connector c, t_xref x, t_connector crel 
where x.Name = 'MOFProps'
and crel.ea_guid = x.Client
and c.ea_guid = '" + this.guid + "'"
+" and x.Description like '%"+this.guid+"%'";
You might be able to use the EA.Connector.CustomProperties to add this property to the association.

Geert

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #8 on: July 29, 2024, 11:22:55 pm »
It's not really that complicated.

You need to make an informationflow (like in the code I shared) and then link it to the association.
The link between the association and the informationflow is made in the t_xref of the association.

This is the code that gets the id's of the other connectors when starting from the information flow.
Code: [Select]
// because access doesn't want to join on the description field (memo) we cannot use proper SQL join syntax
string sqlGetRealization = @"select crel.Connector_ID from t_connector c, t_xref x, t_connector crel 
where x.Name = 'MOFProps'
and crel.ea_guid = x.Client
and c.ea_guid = '" + this.guid + "'"
+" and x.Description like '%"+this.guid+"%'";
You might be able to use the EA.Connector.CustomProperties to add this property to the association.

Geert

I know how to read out info of t_xref, but I am not able yet to write into it (add a new line) as I am missing a GUID. Also: I would rather prefer using the API instead of directly messing into the database.

For the CustomProperties Collection, according to the manual: "Notes: Read Only"

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #9 on: July 29, 2024, 11:52:36 pm »
You can simply generate a new GUID see https://stackoverflow.com/questions/968756/how-to-generate-a-guid-in-vbscript

In case of the custom properties. It says read-only on all collections (as you are not allowed to replace this collection with another collection)

The items in the collection are read-write. https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/customproperties.html

Geert



Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #10 on: July 30, 2024, 05:56:01 pm »
As I apparently have an issue with the forum, that it does not let me post anything anymore...
"CleanTalk: *** Forbidden. Sender blacklisted. You sent forms too often. Please wait a few minutes. Please enable JavaScript. Anti-Spam by CleanTalk. ***"

I just wanted to write here:

So I got some results:

With StartPort <-> EndPort being the two ports between which I create the connector with the Information flow on it

Code: [Select]
Dim newInfoFlow As EA.Connector
Set newInfoFlow = StartPort.Connectors.AddNew("new flow name", "InformationFlow")
newInfoFlow.SupplierID = EndPort.ElementID

Dim newBlock As EA.Element
Set newBlock = Repository.GetElementByGuid("{5139AD62-91C5-4bdd-98ED-8C7252F27DFB}")     <-- Block GUID of an interfaceBlock (that includes a Flow Property)

newInfoFlow.Update()

newInfoFlow.ConveyedItems.AddNew newBlock.ElementGUID , ""

newInfoFlow.Update()
newConnector.Update()

setGUIDsInfoFlowsToConnector newConnector, newInfoFlow.ConnectorGUID

newInfoFlow.Update()
newConnector.Update()

With the additional function:

Code: [Select]
' Set GUIDs of conveyed information flows on one connector by sqlQuery
function setGUIDsInfoFlowsToConnector(connectorToPutInfoFlows, InfoFlows)
Dim newGUID
newGUID = CreateGUID()
Dim sqlQuery
sqlQuery = "INSERT INTO t_xref (XRefID, Name, Type, Visibility, Behavior, Partition, Description, Client, Supplier) Values ('" & newGUID & "','MOFProps', 'connector    property','public','abstraction','0','" & InfoFlows & "','"& connectorToPutInfoFlows.ConnectorGUID &"','<none>')"
Repository.Execute(sqlQuery)
end function

I would just like to omit the SQLquery as I am not completely sure if all the values I write into it are right in all cases (e.g. I have no clue what the Partition value is or does). Unfortunately I was not able jet to find the API function, to do that.

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #11 on: August 01, 2024, 07:42:53 pm »
So I tried with custom properties, but that does not seem to include the information of the info flow on the connector.
Basically I do not see any function or property in the API describtion that tells me anything about the t_xref information combination (what I am currently doing by writing intoSQL)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Conveyed Items to a connector
« Reply #12 on: August 01, 2024, 08:03:37 pm »
So I tried with custom properties, but that does not seem to include the information of the info flow on the connector.
Basically I do not see any function or property in the API describtion that tells me anything about the t_xref information combination (what I am currently doing by writing intoSQL)
It is quite possible that this property has not been exposed in the API. It wouldn't be the first.

To be sure you can contact support at [email protected]

Geert

ScriptUser

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Adding Conveyed Items to a connector
« Reply #13 on: August 07, 2024, 04:28:29 pm »
Just as a final note on this one: Sparx support confirmed that there is indeed no possibility to do that by API.  :-[