Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: matthex on February 17, 2014, 11:23:19 pm
-
I want to add notes to connectors in an Enterprise Architect diagram programmatically. So far I only managed to add notes to elements with the following code snippet:
foreach (EA.Element element in Package.Elements)
{
foreach (EA.Connector conn in element.Connectors)
{
EA.Element newNote = Package.Elements.AddNew("MyNote", "Note");
newNote.Notes = "Some string";
newNote.Update();
//position calculation is left out here
EA.DiagramObject k = diagram.DiagramObjects.AddNew(position, "");
k.ElementID = newNote.ElementID;
k.Sequence = 9;
k.Update();
EA.Connector newConn = newNote.Connectors.AddNew("NewLink", "NoteLink");
newConn.SupplierID = conn.SupplierID;
newConn.Update();
EA.DiagramLink newLink = diagram.DiagramLinks.AddNew("newLink", "NoteLink");
newLink.ConnectorID = newConn.ConnectorID;
newLink.Update();
The image maybe makes it more clear what I actually want:
http://www.directupload.net/file/d/3536/6bkijpg2_png.htm
My question is: How do I get the note attached to the connector? I assume I have to change this line "newConn.SupplierID = conn.SupplierID;", but "newConn.SupplierID = conn.ConnectorID" causes an exception. I would be very happy if someone could help me!
Best regards
-
You need to set PDATA4 = "idref1=<id>;" where <id> is the Connector_Id
q.
-
How do I set this property?
connector.MiscData[3] is read-only.
-
Repository.Execute(SQLUpdateString)
Geert
-
I tried the following code, but it seems to have no effect, newConn.MiscData[3] is not updated:
EA.Connector newConn = newNote.Connectors.AddNew("NewLink", "NoteLink");
newConn.SupplierID = conn.SupplierID;
Repository.Execute("UPDATE t_object SET PDATA4 = \"idref1="+conn.ConnectorID+";\" WHERE Object_ID = "+newConn.ConnectorID);
newConn.Update();I am very new to the development with EA - and I appreciate your help!
Edit:
I guess I have to update PDATA4 for the Note, not the connector. If I understand the PDATA4 entry correctly, we do not need any connectors here. But even this update of PDATA4 for the note does not work:
Repository.Execute("UPDATE t_object SET PDATA4 = \"idref1="+conn.ConnectorID+";\" WHERE Object_ID = "+newNote.ElementID); does not have an effect.
-
It's a bit tricky. The SQL update bypasses the API. The Connector.Update will have a contra-productive effect as it undos the SQL update. So just call the SQL update and the reload the diagram. That should work.
You might have a look in my Inside book to understand more of those details.
q.
-
Thank you so much for you help!
This code works now as intended:
EA.Element newNote = Package.Elements.AddNew("MyNote", "Note");
newNote.Notes = "Some String";
newNote.Update();
Repository.Execute("UPDATE t_object SET PDATA4 = \"idref1=" + conn.ConnectorID + ";\" WHERE Object_ID = " + newNote.ElementID);
diagram.Update();