Book a Demo

Author Topic: Create a note element programmatically  (Read 3206 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Create a note element programmatically
« on: March 08, 2015, 07:04:07 pm »
Hello,

I would like to create programmatically (using C#) a note element on a diagram, and relate it to an existing diagram element.

As I see in t_objects, there is no hint in the note element to the element it is related to.

Any ideas?

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: Create a note element programmatically
« Reply #1 on: March 08, 2015, 09:55:31 pm »
Found the answer:

There are 3 steps:
Create an element.
Create an appropriate diagram object.
Create a connector between the note and the other element.

Code: [Select]

//Add note element to the package where the opened diagram is located
EA.Package packageOfOpenedDiagram = connectToDB.GetRepository.GetPackageByID(openedDiagram.PackageID);
EA.Element newNote = packageOfOpenedDiagram.Elements.AddNew("NoteCreatedByAddin", "Note") as EA.Element;
newNote.Notes = "Original element was replaced with by addin";
newNote.Update();

//Add the new note onto the opened diagram
string position = "1000";// calculate position
EA.DiagramObject noteAsDiagramObject = openedDiagram.DiagramObjects.AddNew(position, "") as EA.DiagramObject;
//Set the new diagram object to refer to the new note element
noteAsDiagramObject.ElementID = newNote.ElementID;
noteAsDiagramObject.Sequence = 9;
noteAsDiagramObject.Update();
                                                                        
//Add connector between element on diagram and the new note
EA.Connector newConnector = lastSelectedElement.Connectors.AddNew("ConnectorCreatedByAddin", "Connector") as EA.Connector;
newConnector.Type = "NoteLink";
newConnector.ClientID = newNote.ElementID;
newConnector.SupplierID = originalElement.ElementID;
newConnector.Update();