Book a Demo

Author Topic: Syntax for adding a connector?  (Read 5095 times)

Tim Twe

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
    • View Profile
Syntax for adding a connector?
« on: May 25, 2010, 09:00:27 pm »
      Hi,

Whats the syntax for correctly adding a connector?


       var c as EA.Connector;
      c = element.Connectors.AddNew( "", "" );
      c.Alias = "Generated";
      c.Type = "CommunicationPath";
      c.ClientID = elementAlpha.ElementID;
      c.SupplierID = elementBeta.ElementID;
      c.Update();
      elementAlpha.Connectors.Refresh();

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Syntax for adding a connector?
« Reply #1 on: May 25, 2010, 09:36:23 pm »
You have to tell EA what type of connector you are adding.
I think the allowed parameters are strings containing the name of the type such as "Association" or "Dependency".
Look at the help page for connector to find the different types.

Geert

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: Syntax for adding a connector?
« Reply #2 on: May 26, 2010, 08:52:54 am »
Here's an example of how to create a connector in JScript.

Code: [Select]
/*
 * Creates a connector between supplier and client
 */
function createConnector( clientElement , supplierElement )
{
      // Assign the client and supplier IDs
      var clientID = clientElement.ElementID;
      var supplierID = supplierElement.ElementID;
      
      // Get the connectors collection
      var connectors as EA.Collection;
      connectors = clientElement.Connectors;
      
      // Create a new connector and set the appropriate details
      var c as EA.Connector;
      c = connectors.AddNew( "", "Association" );
      c.ClientID = clientID;
      c.SupplierID = supplierID;
      c.Direction( "Unspecified" );
      c.Update();

      //      
      // OPTIONAL: Set details on the connector ends
      //

      // Set details on the client connector end
      var clientEnd as EA.ConnectorEnd;
      clientEnd = c.ClientEnd;
      clientEnd.Role = "";
      clientEnd.Cardinality = "";
      clientEnd.Navigable = true;
      clientEnd.Update();
      
      // Set details on the supplier connector end
      var supplierEnd as EA.ConnectorEnd;
      supplierEnd = c.SupplierEnd;
      supplierEnd.Role = "";
      supplierEnd.Cardinality = "1";
      supplierEnd.Navigable = true;
      supplierEnd.Update();
      
      c.Update();
}

« Last Edit: May 26, 2010, 08:58:08 am by mfraser »
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

Tim Twe

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
    • View Profile
Re: Syntax for adding a connector?
« Reply #3 on: May 26, 2010, 07:23:50 pm »
That you, that is absolutely great.

You dont have a repository like http://www.exampledepot.com do you ?

-Tim

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: Syntax for adding a connector?
« Reply #4 on: May 27, 2010, 09:03:27 am »
EA itself ships with an example repository. Open up the Scripting window (View | Scripting from the main menu) and check out the Local Scripts group.

For more specialised scripts check out the Community Resources section of the EA Community site http://community.sparxsystems.com/resources
« Last Edit: May 27, 2010, 09:03:52 am by mfraser »
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8