Book a Demo

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

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #15 on: October 07, 2020, 12:25:52 pm »
qwerty, thanks for your question.
I am currently working on an incremental data model 'reverse-engineeror' outside of sparx  that auto-generates a jscript as SPARX 'plug-in' by comparing a target database against the data model in sparx for a specific package. Therefore the newly created connector may be used by other code within the same run session but on a deferent function of the script, depending on the data model difference at the run time.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: creating connector using script
« Reply #16 on: October 07, 2020, 02:46:00 pm »
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!
The "Read Only" applies only to the object, not it's properties. theElement.Connectors is read only in exactly the same way.

You can write:
Code: [Select]
newConnector.ClientEnd.Role = "something";
You can't write:
Code: [Select]
newConnector.ClientEnd = otherConnector.ClientEnd;

peigee

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: creating connector using script
« Reply #17 on: October 07, 2020, 04:37:14 pm »
Thank you Eve. I have also found this by reading Aaron B's earlier post about his sample FK connector code. Now all sorted as per below:

         var Connectors as EA.Collection;
         Connectors = theElement.Connectors;
         var newConnector as EA.Connector;
         newConnector=Connectors.AddNew(c_keycols+"="+c_r_keycols+")","Association");
         newConnector.SupplierID=r_element.ElementID;
         newConnector.StyleEx = "FKINFO=SRC=" + newMethod.Name + ":DST=" + c_r_pkname + ":;";
         newConnector.Direction = "Source -> Destination";
         newConnector.StereotypeEx = "EAUML::FK";
         newConnector.ClientEnd.Role = newMethod.Name;
         newConnector.ClientEnd.Cardinality = "0..*";
         newConnector.SupplierEnd.Role = c_r_pkname;
         newConnector.SupplierEnd.Cardinality = "1";
         newConnector.Update();