Book a Demo

Author Topic: Package and element  (Read 7567 times)

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Package and element
« on: August 24, 2008, 09:25:52 am »
Hi,

I am realatively new to EA. I want to update lets say a diagram in EA through c#. At the time of updating i do not know that the source elment(which contains the diagram) will be a package or a elment. Do i need to handle these cases differently. What if i access element by id and just update the diagram. What is the difference beween package.Diagram and package.Element.Diagram ?

Please guide.
Thanks.

jkorman

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Package and element
« Reply #1 on: August 24, 2008, 11:37:25 am »
You need to look at the following first

http://www.sparxsystems.com/EAUserGuide/index.html?addandmanagediagrams.htm

From the example
Code: [Select]
  diagram = package.Diagrams.AddNew("Scenerios","Use Case")

or
   // Doesn't really matter where you get your element from
   diagram = element.Diagrams.AddNew("Scenerios","Use Case");  

   If not diagram.Update Then
       Console.WriteLine(diagram.GetLastError)
   End if
   diagram.Notes = "Hello there this is a test"

   diagram.update()


Once you have a diagram attached to something, you can then add stuff to it.

Hope this helps, Jim

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Package and element
« Reply #2 on: August 24, 2008, 04:20:40 pm »
Thanks Jim.

My question was:
Is there any difference between
diagram = package.Diagrams.AddNew("Scenerios","Use Case")
&
diagram = package.Element.Diagrams.AddNew("Scenerios","Use Case")
What differnece do it makes whether I add diagram to a package or an element associated with a package.
I have a another query; will the ID, guid of the package and the element associated with the package with the element will be same or it will be different.
I mean package.packageID & pacakage.packageGuid will be same as package.element.ElementID & package.Element.ElementGUID or it will be different?
It will of grate help if you can suggest Which table in database can I look to verify the same.
Thanks.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Package and element
« Reply #3 on: August 25, 2008, 02:35:42 am »
The unfortunate answer it that sometimes it will matter and sometimes it won't.

The good news is that you will (or should) get an error if you do it the wrong way in cases where it matters.

The general rule is that things that relate to the element-like features of a package (tombstone stuff) should be handled via the Element property. Things that deal with the structure of the project - where the fact that you're dealing with a package (and not 'just any' element) is significant - should go through the Package element itself.

In the case of the Diagrams collection you can generally do it either way. First, both packages and elements can contain diagrams. Second, they pretty much handle the diagrams the same way. Third and perhaps most important, the diagrams collection is kept elsewhere, and each diagram references its owner; the reference to a GUID will work for both the Package and its underlying element, since the same GUID is used for both.

David
No, you can't have it!

utkarsh

  • EA User
  • **
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: Package and element
« Reply #4 on: August 25, 2008, 02:48:06 am »
Can you tell me specifically which things will work for package and which will work with element associated with the package. From where I can get this list?  I took diagram as a example, i need much more than it.

One more question: How can i know what type of elements can contain diagrams?

Thanks for the help.  :)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Package and element
« Reply #5 on: August 25, 2008, 05:04:42 am »
Your first question is best answered by looking at the SDK documentation in EA help. That's the authoritative source. A good rule of thumb is that if what you want does not appear under Package it is probably obtained from Package.Element.

For the second question, you should experiment. Pretty much anything can contain diagrams, but EA might not act as you'd expect for some types of diagram parents.

Try this experiment. Create a test project by hand. Create a diagram and add various types of elements to it. [Remember you can control right-click to add elements you'd not normally see on your diagram type.]

For each element, right-click and choose Add from the context menu. If you see a set of diagram types at the bottom of the Add context menu, or if you see an option to add a diagram at the bottom, it is a good bet that EA will react well if you add diagrams to this element type. Note that EA is generally benign when you add a diagram that's not one of the 'expected' types on the context menu, so you can usually mix and match as you wish. [You can do this by hand if you want, by opening the child diagram and using the main menu to modify it via Diagram | Change Type. You can also do this at diagram creation time via the Add Diagram option on the context Menu.]

David
No, you can't have it!