EA handles note links to connectors very differently from note links to elements.
Connectors always run between two elements. In your example, there are four elements (two of type Activity
named O1 and O2, and two of type Note
; these are usually nameless) and three connectors (O1 - O2, "This is what I have" - O2, and one from O1 running off the edge of the image).
The thing that looks like a connector from "This is what I want" to the O1 - O2 connector is not, in fact, a connector at all -- it just looks like one. In the GUI, the link to a connector is unresponsive and you can't bring up a properties dialog for it. This is why.
The fact that the note is linked to the connector is stored in the note element itself, in the MiscData
collection. What you need to do is add the string idref=<connector_id>;
to MiscData(3)
. You may also need to set the Note
's Subtype
field to 1.
However, MiscData
is read-only so you'll have to go into the database and update t_object
(where elements are stored) directly. MiscData
in the API corresponds to PDATA1
etc in the table. Note that the indices differ by one, so MiscData(0)
corresponds to PDATA1
, etc.
You will also need to use the undocumented Repository.Execute()
since Repository.SQLQuery()
only allows select
statements.
So the following should work:
foreach (EA.Connector conn in element.Connectors) {
EA.Element newNote = Package.Elements.AddNew("MyNote", "Note");
newNote.Subtype = 1;
newNote.Notes = "Some string";
newNote.Update();
repository.Execute("update t_object set PDATA4='idref=" + conn.ConnectorID + ";' " +
where Object_ID=" + newNote.ElementID);
//position calculation is left out here
EA.DiagramObject k = diagram.DiagramObjects.AddNew(position, "");
k.ElementID = newNote.ElementID;
k.Sequence = 9;
k.Update();
}
You may need to set the element subtype after the database update, I'm not sure.
Element.Subtype
values are undocumented in the API, as are the contents of Element.MiscData
, so this solution isn't future-proof (but it's very unlikely EA will ever change the way it handles these things).