Book a Demo

Author Topic: Correct way to replace a diagram  (Read 3250 times)

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Correct way to replace a diagram
« on: March 16, 2010, 02:32:57 am »
Hi everyone
For a given element I want to discover if a diagram exists for a given name and if so replace it with a new one of that name
What I am doing is the following, it works BUT I get a warning dialog in EA stating that the underlying model data is out of date and to press OK to do a refresh. Doing so results in the model that I want, but obvouisly I dont want the dialog to appear.

What have I missed

Graham
Code: [Select]
short diagramIndex = 0;
foreach (EA.Diagram diag in CurrentlySelectedElement.Diagrams)
{
    if (diag.Name == CurrentlySelectedElement.Name + " xxxx")
    {
        CurrentlySelectedElement.Diagrams.DeleteAt(diagramIndex, true);
        CurrentlySelectedElement.Diagrams.Refresh();
        CurrentlySelectedElement.Update();
        break;
    }
    diagramIndex++;
}
EA.Diagram newDiagram = (EA.Diagram)
                                    CurrentlySelectedElement.Diagrams.AddNew
                                   (CurrentlySelectedElement.Name + "
                                     xxxx", "Analysis");
                  
newDiagram.DiagramObjects.Refresh();
newDiagram.Update();
CurrentlySelectedElement.Diagrams.Refresh();
CurrentlySelectedElement.Update();
Repository.OpenDiagram(newDiagram.DiagramID);

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: Correct way to replace a diagram
« Reply #1 on: March 16, 2010, 07:35:16 pm »
Graham,

Look for refresh/reload funtionality in (i think) the Repository class.
I'm guessing that should help in your case.

Geert

SomersetGraham

  • EA User
  • **
  • Posts: 376
  • Karma: +1/-0
    • View Profile
Re: Correct way to replace a diagram
« Reply #2 on: March 16, 2010, 09:20:54 pm »
Thanks Geert
Working well now thanks

Graham
Using V12