Search code examples
enterprise-architect

Updating the connector creation in diagram link table


We have created the connectors through ad-din and the connectors will be auto updated in the diagram.But the problem is when we try to find the connector in the diagram link table the connector will not be updated.So how can we parallel y create the connectors and add the line style to the connector diagram link.

Connectors are created using the below API

EA.Connector con = pPortsource.Connectors.AddNew("", "Association");
con.SupplierID = Porttarget.ElementID;
con.Update(); 

using this above API whether the diagram link in the diagram is automatically created or should we use the below code to create the diagram link

  EA.DiagramLink link=Diagram.AddNew("","");
  link.ConnectorID=con.ConnectorID;
  Link.update();

Solution

  • Having grasped what your basic issue is: setting a default line style. You would do that with Tools > Options > Links > Default Style > Routing and/or Tools > Options > Links > Generalization link style Default = Tree. This is what EA offers.

    In case you want something else, you are more or less lost, except you put a lot of tricky effort in your add-ins. Why that? Consider you add a new connector. This will not only appear in the diagram you are currently working on, but also in all diagrams where the two connected elements appear. Here I started experimenting and can confirm the OP's issue:

    If you create a new connector without a diagram visible, EA will not create an entry in t_diagramlinks. It will then only create an entry if you modify the line style. A missing entry lets EA create a default connector style. Now, what you could do is to issue

    Repository.Execute("INSERT INTO t_diagramlinks (diagramId, connectorId, style) VALUES (<diagramId>, <con.connectorID> 'Mode=2;')");
    

    immediately after connector creation. This will set auto-routing for the connector in the single diagram. You can use a simple query to find all diagrams where the two connected elements are also present and repeat the above SQL accordingly. To make it complete you would also need to subscribe to EA_OnPostNewDiagramObject since that might also be the cause of the connector to appear on a diagram. I haven't tested this and whether EA will immediately create an entry in t_diagramobject so you could tweak that and whether you would need to reload the diagram to make the change visible. In any case, lots of tweaking ahead and it might spoil the already questionable EA user interface.

    Original answer

    In order to create new connectors and have them displayed you would use this (sorry for the Perl) code:

    my $e = $rep->GetElementByGuid("{EB86E518-5BDC-477b-8CF8-2BEE0A102CF7}");
    my $e1 = $rep->GetElementByGuid("{28636F81-2B1E-40af-A777-81ECEB067F31}");
    my $con = $e1->Connectors->AddNew("", "Dependency");
    $con->{SupplierId} = $e->ElementId;
    $con->Update();
    
    my $dia = $rep->GetCurrentDiagram();
    $rep->ReloadDiagram ($dia->DiagramID);
    

    This will create a new link as desired and EA will show it after the diagram is reloaded. You don't have to fiddle will DiagramLinks. The are only needed if you want to tweak connectors. That is, to hide them or add bends and the like.