Book a Demo

Author Topic: Adding a text element to a diagram  (Read 5203 times)

Fabio Riera

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Adding a text element to a diagram
« on: July 11, 2013, 10:56:20 pm »
It seems a simple task. How I add a text note to a diagram from my add-in? I found a collection called "Diagram.DiagramObjects", but I can't add a new element there.

Thanks in advance.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Adding a text element to a diagram
« Reply #1 on: July 11, 2013, 11:04:13 pm »
Hi Fabio,

the following snippet shows you how to add a note, connect to an element and visualize the note of the element.
Code: [Select]
                       Repository.SaveDiagram(dia.DiagramID);
                      
                       EA.Element elNote = null;
                       try
                       {
                           elNote = (EA.Element)pkg.Elements.AddNew("", "Note");
                           elNote.Update();
                           pkg.Update();
                       }
                       catch { break; }

                       // add element to diagram
                       // "l=200;r=400;t=200;b=600;"

                       // get the position of the Element
                       EA.DiagramObject diaObj = null;
                       foreach (EA.DiagramObject dObj in dia.DiagramObjects) {
                           if (dObj.ElementID == el.ElementID)
                           {
                               diaObj = dObj;
                               break;
                           }
                       }
                          int left = diaObj.left + 2*(diaObj.right - diaObj.left);
                       int right = diaObj.right + 2 * (diaObj.right - diaObj.left);

                       string position = "l=" + left.ToString() +";r=" + right.ToString() + ";t=" + diaObj.top.ToString() + ";b=" + diaObj.bottom.ToString() + ";";
                       EA.DiagramObject diaObject = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, "");
                       dia.Update();
                       diaObject.ElementID = elNote.ElementID;
                       diaObject.Update();
                       pkg.Elements.Refresh();
                       // make a connector
                       EA.Connector con = (EA.Connector)el.Connectors.AddNew("test", "NoteLink");
                       con.SupplierID = elNote.ElementID;
                       con.Update();
                       el.Connectors.Refresh();
                       Util.setElementHasAttchaedLink(Repository, el, elNote);
                       Repository.ReloadDiagram(dia.DiagramID);

                   }


Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Fabio Riera

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Adding a text element to a diagram
« Reply #2 on: July 12, 2013, 12:06:18 am »
Thanks! Text added successfully!
Is there a document that lists which html tags are allowed in the .Notes property of an Element?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a text element to a diagram
« Reply #3 on: July 12, 2013, 08:29:43 am »
Use Repository.GetFormatFromField and it's pendant.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding a text element to a diagram
« Reply #4 on: July 12, 2013, 03:28:57 pm »
Yes, don't try to do EA notes formatting yourself, but use use either HTML or RTF to do formatting and let EA convert it to it's own format using the GetFormatFromField and GetFieldFromFormat operations.

Geert