Book a Demo

Author Topic: Correct way of adding objects on the diagram  (Read 3622 times)

Alex@Net

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Correct way of adding objects on the diagram
« on: March 31, 2010, 02:25:40 pm »
Hello!

I looking for the correct method of adding elements on the diagram.

My code:
Code: [Select]
var diagram = repository.GetCurrentDiagram();
var package = repository.GetPackageByID(diagram.PackageID);
var element = (EA.Element)package.Elements
    .AddNew(@class.Name, "Class");
element.Update();
var obj = (EA.DiagramObject)diagram.DiagramObjects
    .AddNew(element.Name, "DiagramObject");
obj.ElementID = element.ElementID;
obj.Update();
repository.ReloadDiagram(diagram.DiagramID);

It works fine if you just open the diagram and add the object. But when you open the diagram, move the elements on it and then call this function, ReloadDiagram will revert the positions of the elements.

ReloadDiagram is required because it shows added element on the diagram.

My EA version is 7.5.848.

Thanks,
Alex
« Last Edit: March 31, 2010, 02:27:22 pm by alexatnet »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Correct way of adding objects on the diagram
« Reply #1 on: March 31, 2010, 03:06:33 pm »
The only option I can think of is to call Repository.SaveDiagram() before you call ReloadDiagram().  This should commit any changes that have been made by the user before you reload the diagram to see the new element(s) that you have just added.

Alex@Net

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Correct way of adding objects on the diagram
« Reply #2 on: April 01, 2010, 11:34:09 am »
Ok. I solved the issue by saving the diagram before adding class on it. Thanks.
« Last Edit: April 01, 2010, 11:34:28 am by alexatnet »