Book a Demo

Author Topic: To insert a Symbol in EA Diagram  (Read 5617 times)

syedmohdtauseef

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
To insert a Symbol in EA Diagram
« on: September 30, 2006, 05:05:46 am »
Hi,

I am creating diagrams in EA hierarchy by C#.
i am using following command for it :

p.Element.Diagrams.AddNew("ZABBAR","Use Case");
p.Element.Diagrams.Refresh();
p.Update();

where p is package reference where we want to add diagram

But after ruuning this code no diagram is created

Help .....

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: To insert a Symbol in EA Diagram
« Reply #1 on: October 01, 2006, 04:25:42 pm »
The AddNew call returns a reference to the object being created. You need to grab this reference, and run Update() on it to commit it to the repository.  Something like the following:

Code: [Select]
EA.Diagram diag = p.Element.Diagrams.AddNew("ZABBAR","Use Case");
diag.Update();
p.Element.Diagrams.Refresh();
p.Update();

Hope this helps. :)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: To insert a Symbol in EA Diagram
« Reply #2 on: October 02, 2006, 05:31:00 am »
Aaron,

Is the final line -- p.Update(); -- in your code example strinctly required?
No, you can't have it!

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: To insert a Symbol in EA Diagram
« Reply #3 on: October 02, 2006, 04:54:54 pm »
Probably not.  ;D  Just copied the block of code from the original question and inserted the required line.  In this context, no, the last line is not required to commit the new diagram.  Neither is the Diagrams.Refresh() call strictly speaking, but that should be called if the user is going to access the collection again afterwards.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: To insert a Symbol in EA Diagram
« Reply #4 on: October 03, 2006, 04:31:11 am »
Just making sure.

I do agree with Aaron's comment about the Refresh() call though. My experience is that it is relatively low in performance cost, and the collection needs to be refreshed before you next reference it via the automation interface. Generally, if you've added an element there's a good chance you'll want to look at it again soon.

Remember that you can a bunch of elements to the same parent collection, remembering to call Update() for each element, and then make a single call to Refresh() on the collection. That saves on some time.

For some reason you can have the Delete() funtion work both ways, but the AddNew does not. If Sparx is listening, please consider this for a future improvement...

David
No, you can't have it!