Book a Demo

Author Topic: Add note to a diagram  (Read 4409 times)

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Add note to a diagram
« on: March 10, 2010, 07:37:35 pm »
Hi Everyone
I have gone through all the examples and searched this forum but I cannot find how to add a note element to a diagram.
Please can someone point me in the right direction

Thanks

Graham
Using V12

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add note to a diagram
« Reply #1 on: March 10, 2010, 07:54:42 pm »
Graham,

In order to put something on a diagram it first needs to exist as an Element.
So first create the element of type note (in the package containing the diagram)
Then create a new DiagramObject on the diagram and link that to the note with the ElementID

I think you probably best set the diagramID on the element to indicate that this note belongs to the diagram, but that is something you'll have to test yourself.

Geert

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Re: Add note to a diagram
« Reply #2 on: March 10, 2010, 09:01:37 pm »
Hi Geert
I have created the note element and diagram as you suggested but the note does not appear on the diagram. The new element is created and exists in the model. I could not find a way of linking the diagram id to the element
Why does it not appear ? - here is he code
Code: [Select]
// Get Package and create new element
int packageID = CurrentlySelectedElement.PackageID;
EA.Package package = Repository.GetPackageByID(packageID);
EA.Element noteElement = (EA.Element)package.Elements.AddNew("newNote", "Note");
noteElement.Notes = "This text was added by me";
noteElement.Update();
package.Elements.Refresh();

// Create the new diagram
EA.Diagram diagram = (EA.Diagram)CurrentlySelectedElement.Diagrams.AddNew(CurrentlySelectedElement.Name + " Robustness", "Analysis");

// Add a new diagram object
EA.DiagramObject newDiagramObject = (EA.DiagramObject)diagram.DiagramObjects.AddNew("", "");
newDiagramObject.ElementID = noteElement.ElementID;
newDiagramObject.Update();
                    
//Display the diagram
diagram.DiagramObjects.Refresh();
diagram.Update();
Repository.OpenDiagram(diagram.DiagramID);
Using V12

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Re: Add note to a diagram
« Reply #3 on: March 10, 2010, 09:21:42 pm »
Hi
Found the problem - an Update is required after creating the diagram.
Are there any rules for when update and refresh should be called?

Graham
Using V12

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add note to a diagram
« Reply #4 on: March 10, 2010, 11:03:32 pm »
No, no rules.
Just remember that update() saves things to the database.
Often you cannot link something to it without having saved it to the database before.
Refresh() is only necesarry if you plan the collection in memory later on in the program.
In your example the refresh() is not necesarry (if the operation ends there)

Geert