Book a Demo

Author Topic: Create Element  (Read 4306 times)

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Create Element
« 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!

alext

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Create Element
« Reply #1 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?

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Create Element
« Reply #2 on: March 17, 2009, 12:27:34 am »
You should be able to set all these properties. Try do it after calling element.Update().

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create Element
« Reply #3 on: March 17, 2009, 01:05:07 am »
And then remember to call Update() again, to save the new property values.
No, you can't have it!