Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: blue5teel on September 29, 2010, 07:02:16 pm
-
Hello community,
i am adding an diagram and some elements to my project with EA API.
My elements and diagram show up in the repository tree but my diagram does not contain any of my elements.
See below for my code:
private void processRequirements()
{
EA.Diagram diagram = (EA.Diagram)selectedPackage.Diagrams.AddNew("Anforderungsdiagramm", "Logical");
selectedPackage.Update();
foreach (Requirement r in requirementList)
{
EA.Element packageElement = (EA.Element)selectedPackage.Elements.AddNew(r.ID, "Class");
packageElement.Notes = r.description;
packageElement.Update();
packageElement.Refresh();
selectedPackage.Update();
string position = ("l=200;r=400;t=200;b=600;");
EA.DiagramObject diagramObject = (EA.DiagramObject)diagram.DiagramObjects.AddNew(position, "Class");
diagramObject.ElementID = packageElement.ElementID;
diagramObject.Update();
selectedPackage.Update();
selectedPackage.Elements.Refresh();
diagram.Update();
diagram.DiagramObjects.Refresh();
}
I appreciate any hints. thx :-/
-
tried to reload the diagram?
Repository.ReloadDiagram(int DiagramId)...
-
Got the solution:
Updating the diagramID of my new diagramobjects:
EA.DiagramObject diagramObject = (EA.DiagramObject)diagram.DiagramObjects.AddNew(position, "Class");
diagramObject.ElementID = packageElement.ElementID;
diagramObject.DiagramID = diagram.DiagramID;
I think Sparx' employees should update their code samples. Sample "Add and Manage Diagrams" doesnt say anything about setting the DiagramID.
Thx for your help.
-
This seems like a bug to me.
If you add a diagramObject to the Diagrams DiagramObjects collection it should at least already fill in the DiagramID on the new DiagramObject.
It already does so for other collections...
Geert