Author Topic: creating connector using script  (Read 14067 times)

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
creating connector using script
« on: July 08, 2011, 01:11:56 am »
Hi guys,

Is it possible to create connector using scripts. An example will help ....

TIA

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: creating connector using script
« Reply #1 on: July 08, 2011, 09:05:55 am »
You need to call AddNew() on an element's Connectors collection. So something like:

Code: [Select]
dim conn as EA.Connector
set conn = source.Connectors.AddNew("Association","")
conn.Start_Object_ID = source.Object_ID
conn.End_Object_ID = target.Object_ID
conn.Update()
source.Connectors.Refresh()

My morning caffeine hasn't kicked in yet, so this could well be rubbish: Debugging is left as an exercise for the reader ;)
The Sparx Team
[email protected]

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: creating connector using script
« Reply #2 on: July 08, 2011, 10:04:49 am »
Some corrections to KP's code   ;)

Code: [Select]
dim source as EA.Element
dim target as EA.Element
dim conn as EA.Connector

' set source and target to reference valid Elements in your repository

' ClientID = source end, SupplierID = target end
' source end is already set based on the element that owns the Connectors collection.  Only need to set SupplierID.

set conn = source.Connectors.AddNew("", "Association")
conn.SupplierID = target.ElementID
conn.Update
source.Connectors.Refresh
target.Connectors.Refresh

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: creating connector using script
« Reply #3 on: July 08, 2011, 10:17:51 am »
Quote
Some corrections to KP's code   ;)
Wow, only 3 mistakes! Thanks :)
The Sparx Team
[email protected]

MV

  • EA User
  • **
  • Posts: 65
  • Karma: +1/-0
    • View Profile
Re: creating connector using script
« Reply #4 on: July 08, 2011, 02:19:19 pm »
Thank you guys...

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #5 on: February 13, 2014, 12:27:21 pm »
Is there a way to achieve the same result using JScript and SQL query especially when you have a single element that has a relationship with a 1000 others?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: creating connector using script
« Reply #6 on: February 13, 2014, 08:17:08 pm »
Why would you want to use SQL? Creating a new connector is independent from the number of already existing connectors.

And yes: JScript will do analogously.

q.

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #7 on: October 06, 2020, 01:19:44 pm »
The replies so far only mentioned the source and target elements (client and supplier id) for the new connector. How to specify the source and target role (attribute sourcerole and destrole in the repository table t_connect) for linking the operation FK and PK, if I want to add a connector for a new FK via java script? I could not find such properties available for the connector object. Here are the sample script I have been experimenting and found out SourceRole and DeskRole are invalid property for the connector:

--after added a new method for the FK operation record (and its parameters) and located the existing source and target element and the target PK operation name:

var Connectors as EA.Collection;
Connectors = theElement.Connectors;
var newConnector as EA.Connector;
newConnector=Connectors.AddNew("","Association");
newConnector.SupplierID=r_element.ElementID;
*newConnector.SourceRole=newMethod.Name;
*newConnector.DeskRole=c_r_pk;
newConnector.Update();
Connectors.Refresh();
target.Connectors.Refresh();

What are the correct properties I shall use to complete an FK constraint addition via Jscript?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13400
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: creating connector using script
« Reply #8 on: October 06, 2020, 03:03:19 pm »

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #9 on: October 06, 2020, 06:39:17 pm »
Thank you Geert. I have tried your suggested two properties before by assigning the FK and PK method.name values (perhaps I should have used method.MethodID?). Anyhow after seeing another post suggesting property StyleEx, I got it working, as follows:

--after added a new method for the FK operation record (and its parameters) and located the existing source and target element and the target PK operation name:

         var Connectors as EA.Collection;
         Connectors = theElement.Connectors;
         var newConnector as EA.Connector;
         newConnector=Connectors.AddNew("","Association");
         newConnector.SupplierID=r_element.ElementID;
         newConnector.StyleEx = "FKINFO=SRC=" + newMethod.Name + ":DST=" + c_r_pkname + ":;";
         newConnector.Update();
         Connectors.Refresh();
         r_element.Connectors.Refresh();

steen.jensen

  • EA User
  • **
  • Posts: 181
  • Karma: +8/-1
    • View Profile
Re: creating connector using script
« Reply #10 on: October 07, 2020, 07:53:47 am »
Wy all those refresh statement??

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: creating connector using script
« Reply #11 on: October 07, 2020, 08:40:36 am »
Because the explanation in EAs help is sub-optimal and people just don't know why to use them. Doing no harm they plaster their code with refesh calls.

q.

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #12 on: October 07, 2020, 10:58:15 am »
The second refresh statement indeed isn't necessary. The first one is for the newly added connector to be navigated to by my subsequent code not listed here.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: creating connector using script
« Reply #13 on: October 07, 2020, 11:43:18 am »
Why navigating in the collection if you have the created connector right at hand? You just created it. Ah, well. Never mind.

q.

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #14 on: October 07, 2020, 11:58:15 am »
Geerty, a good reminder! Just realised while setting StyleEx had created the visual connector in a diagram, it hadn't actually populated values in SourceRole and DestRole of t_connector table, therefore, the FK (Association) connector is still not created correctly.
However your suggested ClientEnd and SuppliedEnd are two readonly properties and wouldn't accept newMethod.MethodID or anything else related to the FK/PK operation records at all.
I am now back to square one!