Author Topic: How to create a connector to a connector (with a script)  (Read 11671 times)

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
How to create a connector to a connector (with a script)
« on: September 14, 2021, 07:02:36 am »
In a drawing it is very straightforward to create a connector between an element and a connector.
However I do not understand how I can do this with a script.
A connector does not have a Connectors collection to add something to;
And if you use the connectorID as value for the SupplierID of a newly created connector it does not get created either.
The main data model of connector only shows a connector linked to an element not to a connector.
I did some debugging and when I inspect a connector linked to another connector the SupplierID is not at all the value of the connector it is linked to.
So I think there is an Element in between linking the connector to the connector and this Element is not visible as such.
However I can find no reference in the documentation if my suspicion is correct and if so which type of Element should be created to link the two connectors.
Anybody did this and can maybe submit a code sniplet?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #1 on: September 14, 2021, 07:15:47 am »
Something along this lines:

Code: [Select]
connector = element1.Connectors.AddNew ("", "Dependency");
connector.SupplierID = element2.ElementID;
connector.Update ();
(from my scripting book)

The connector will automatically appear in all diagrams where both elements are present. You would need to poke diagramLinks for hiding it in certain diagrams.

q.

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #2 on: September 14, 2021, 08:01:06 am »
That is how you create a connector between two elements but it will not work to create an connector between an element and another connector (which is very much possible in the GUI)
Doing some more debugging I found that the element linked to the other side of the connector is a ProxyConnector, but still have to figure out how to attach that to the connector.
But it will be for another day as I have been puzzling all day on this script and solutions will not come today  :-[

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #3 on: September 14, 2021, 08:18:25 am »
Never tried it myself, but it looks like you have to create an object with type 'ProxyConnector' and set its t_object.Classifier_guid to the GUID of the connector that owns it.
The Sparx Team
[email protected]

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #4 on: September 14, 2021, 05:01:10 pm »
Yes, I was not reading carefullly. But it's like KP says. You need that doppelganger object for a connector-connector.

q.

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #5 on: September 15, 2021, 05:44:49 am »
I had a hard time getting this working and it is caused by the fact that the API misses an operation.
The answer is in https://www.sparxsystems.com/forums/smf/index.php/topic,41346.msg249952.html#msg249952

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #6 on: September 15, 2021, 05:46:43 am »
For the people interested this JavaScript works:

function createRelationToConnector(elementParam, connectorParam, paramDiagramPackage, typeOfRelation)
{
   var theConnector as EA.Connector;
   theConnector = connectorParam;
   
   var theElement as EA.Element;
   theElement = elementParam;
   
   var theDiagramPackage as EA.Package;
   theDiagramPackage = paramDiagramPackage;

   Session.Output( "Creating the relation connection.");
   
   // I am confused here on client and supplier because it seems backwards but this way it is correct anyway ...
   var relationConnector as EA.Connector;
   relationConnector = theElement.Connectors.AddNew("", typeOfRelation);
   // now we create a ProxyConnector element to connect the other side to.
   var proxyElement as EA.Element;
   proxyElement = theDiagramPackage.Elements.AddNew("NoteProxy", "ProxyConnector");
   relationConnector.SupplierID = proxyElement.ElementID;
   relationConnector.Update();
   theElement.Connectors.Refresh();
   proxyElement.Connectors.Refresh();
   
   // this repository query sets the t_object.Classifier_guid to the GUID of the connector that owns it.
   // it is a dirty hack as the ClassifierGUID is not editable though the object model.
   Repository.Execute("UPDATE t_object SET Classifier_guid='" + theConnector.ConnectorGUID + "' WHERE Object_ID=" + proxyElement.ElementID + ";");
}

there is NO proxyElement.ClassifierGUID on the API to set in a clean way.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #7 on: September 15, 2021, 06:43:39 pm »
I guess you can do with setting the Classifier in the API. There are two columns, Classifier and Classisifer_guid. The latter is a doppelganger of the first. There's only a faint idea I have seen it in a different context as sort of restore possibility, but not sure. Anyhow, try to go with just seeting the classifier property in the GUI.

q.

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #8 on: October 13, 2021, 10:55:32 pm »
There is only a ClassifierID attribute on the class and that won't accept the GUID. You get an error if you try.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #9 on: October 14, 2021, 04:48:35 am »
No, but it will take the ObjectID happily.

q.

Arnoud_B

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
    • View Profile
Re: How to create a connector to a connector (with a script)
« Reply #10 on: October 14, 2021, 09:02:53 pm »
Well I have changed the Execute:
Repository.Execute("UPDATE t_object SET Classifier_guid='" + theConnector.ConnectorGUID + "' WHERE Object_ID=" + proxyElement.ElementID + ";");

By:
   proxyElement.ClassifierID = theConnector.ConnectorID;
   proxyElement.Update();

However no relationship is created so ClassifierID and ClassifierGUID do not seem to be synonyms in this case.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to create a connector to a connector (with a script)
« Reply #11 on: October 14, 2021, 09:55:56 pm »
Well I have changed the Execute:
Repository.Execute("UPDATE t_object SET Classifier_guid='" + theConnector.ConnectorGUID + "' WHERE Object_ID=" + proxyElement.ElementID + ";");

By:
   proxyElement.ClassifierID = theConnector.ConnectorID;
   proxyElement.Update();

However no relationship is created so ClassifierID and ClassifierGUID do not seem to be synonyms in this case.
No, you can't do that. EA expects an ElementID there, and if you are unlucky the ConnectorID is also an ElementID of a totally different element.

Geert