Book a Demo

Author Topic: Elements added to an Activity Diagram don't appear  (Read 4604 times)

Jeronimo

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Elements added to an Activity Diagram don't appear
« on: December 20, 2010, 09:26:37 pm »
Hello,
I try to write a Jscript which adds an activity diagram to every class and adds for each method of the class an activity to this diagram. Unfortunately the added activities don't appear at the diagram...

[size=10]for(var n = 0; n < methods.Count; n++)
{
    // Get the current method
    var currentMethod as EA.Method;
    var newActivity as EA.Element;
    currentMethod = methods.GetAt(n);
    
    // Create an activity for this method
    newActivity = currentElement.Elements.AddNew(currentMethod.Name, "Activity");
                        
    // Add the activity to the diagram
    var diagramObjects as EA.Collection;
    diagramObjects = activityDiagram.DiagramObjects;
    var activityDiagramObject as EA.DiagramObject;
    activityDiagramObject = diagramObjects.AddNew("l=200;r=400;t=200;b=600;", "");
    activityDiagramObject.ElementID( newActivity.ElementID );
    activityDiagramObject.Update();
    diagramObjects.Refresh();
    Session.Output( "Added activity '" + newActivity.Name + "' to
                             diagram '" + activityDiagram.Name + "'");
    currentElement.Update();
}[/size]


What I'm doing wrong?

bests,
Jeronimo
« Last Edit: December 20, 2010, 09:49:51 pm by jeronimo78 »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Elements added to an Activity Diagram don't ap
« Reply #1 on: December 21, 2010, 12:48:26 am »
Jeronimo,

I think you'll need to user Repository.ReloadDiagram (long DiagramID)
to refresh the contents of the diagram.

Geert

PS. I don't think diagramObjects.Refresh() is usefull in your context.

Jeronimo

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Elements added to an Activity Diagram don't ap
« Reply #2 on: December 21, 2010, 01:50:33 am »
Hello Geert,
thank you for your quick reply! Unfortunately reloading the
Diagram by Repository.ReloadDiagram(activityDiagram.DiagramID)
doesn't help... the diagram is still empty...  :(

bests
Jeronimo

P.S.:
I wish you all a merry Christmas and a happy new year!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Elements added to an Activity Diagram don't ap
« Reply #3 on: December 21, 2010, 08:30:16 am »
Looks like you aren't saving the Activity before trying to add it to the diagram.  So the ElementID will still be zero.

Add newActivity.Update();

I'm also no sure why you are doing currentElement.Update();, as it hasn't been modified anywhere in the loop.

Jeronimo

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Elements added to an Activity Diagram don't ap
« Reply #4 on: January 03, 2011, 07:42:57 pm »
Hello Simon M,

unfortunately saving the activity doesn't help... The activities are just still appearing in the project browser but not in the diagram.

bests,
Jeronimo

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Elements added to an Activity Diagram don't ap
« Reply #5 on: January 03, 2011, 07:50:14 pm »
Jeronimo,

Could you post an update of your code?
We might be able to spot the error.

Geert

Jeronimo

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Elements added to an Activity Diagram don't ap
« Reply #6 on: January 03, 2011, 08:36:38 pm »
Dear all,
i found out whats going wrong... My fault was before the code fragment:
I created a new Diagram, but I didn't save the diagram using the activityDiagram.Update();  -method.
After creating the Diagram I have to save the Diagram before adding elements to it!

Thank you all for your help!  :)