Book a Demo

Author Topic: EA 9: Add Note to Connector [Solved]  (Read 4714 times)

matthex

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
EA 9: Add Note to Connector [Solved]
« 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:

Code: [Select]
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
« Last Edit: February 19, 2014, 01:15:29 am by matthex »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Enterprise Architect 9: Add Note to Connector
« Reply #1 on: February 18, 2014, 03:15:04 am »
You need to set PDATA4 = "idref1=<id>;" where <id> is the Connector_Id

q.

matthex

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Enterprise Architect 9: Add Note to Connector
« Reply #2 on: February 18, 2014, 07:07:11 pm »
How do I set this property?
connector.MiscData[3] is read-only.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Enterprise Architect 9: Add Note to Connector
« Reply #3 on: February 18, 2014, 08:18:33 pm »
Repository.Execute(SQLUpdateString)

Geert

matthex

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Enterprise Architect 9: Add Note to Connector
« Reply #4 on: February 19, 2014, 12:16:15 am »
I tried the following code, but it seems to have no effect, newConn.MiscData[3] is not updated:
Code: [Select]
                               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:
Code: [Select]
Repository.Execute("UPDATE t_object SET PDATA4 = \"idref1="+conn.ConnectorID+";\" WHERE Object_ID = "+newNote.ElementID); does not have an effect.
« Last Edit: February 19, 2014, 12:53:42 am by matthex »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Enterprise Architect 9: Add Note to Connector
« Reply #5 on: February 19, 2014, 12:51:53 am »
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.
« Last Edit: February 19, 2014, 12:52:32 am by qwerty »

matthex

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Enterprise Architect 9: Add Note to Connector
« Reply #6 on: February 19, 2014, 12:58:34 am »
Thank you so much for you help!
This code works now as intended:
Code: [Select]
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();
« Last Edit: February 19, 2014, 01:02:00 am by matthex »