Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: alext on March 16, 2009, 06:52:44 pm

Title: Create Element
Post by: alext on March 16, 2009, 06:52:44 pm
Could anyone tell me what I'm missing?
I see the element getting created in the project tree... but as soon as I refresh the tree, my new element "dissapears".

The idea is to create an element in a package called "Issues" and add the new element in the first diagram found in the "Issues" package.

Here is the code I'm using for this...


EA.Package selectedProject = this.getSelectedProject(repository);
EA.Package issuesModel = (EA.Package)selectedProject.Packages.GetByName("Issues");
EA.Diagram issuesDiagram = (EA.Diagram)issuesModel.Diagrams.GetByName("Issues");
repository.OpenDiagram(issuesDiagram.DiagramID);
EA.Element element = (EA.Element)issuesModel.Elements.AddNew(newEAIssue.getIssueName(), "Issue");
element.Notes = newEAIssue.getNotes();
element.Priority = newEAIssue.getPriority();
element.Status = newEAIssue.getStatus();
element.Type = newEAIssue.getType();
element.Update();
issuesModel.Update();
selectedProject.Update();
issuesModel.Elements.Refresh();
repository.GetProjectInterface().ReloadProject();

EA.DiagramObject diagramObject = (EA.DiagramObject)issuesDiagram.DiagramObjects.AddNew("", "Issue");
diagramObject.ElementID = element.ElementID;
diagramObject.top = 100;
diagramObject.left = 100;
diagramObject.bottom = 150;
diagramObject.right = 200;
diagramObject.Update();
issuesDiagram.DiagramObjects.Refresh();
repository.GetProjectInterface().ReloadProject();


What am I doing wrong or not doing at all?

Thank you!
Title: Re: Create Element
Post by: alext on March 16, 2009, 09:44:04 pm
Okay...the reason why the item disappears is because I was trying to set the Type of the object with :

element.Type = newEAIssue.getType();

The type property that I'm refering to here is Display, Functional, Performance... the different Issue types.
Unfortunatly I can't set this property ... nor can I set
  element.Priority or
  element.Status

Is this even possible from C#? Or will I have to set these properties manually in EA?
Title: Re: Create Element
Post by: Frank Horn on March 17, 2009, 12:27:34 am
You should be able to set all these properties. Try do it after calling element.Update().
Title: Re: Create Element
Post by: «Midnight» on March 17, 2009, 01:05:07 am
And then remember to call Update() again, to save the new property values.