Book a Demo

Author Topic: object types  (Read 4490 times)

Chris Tatem

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
object types
« on: February 26, 2010, 03:19:22 am »
The documentation for the AI says (in part ;) ):
"The ObjectType enumeration identifies Enterprise Architect object types even when referenced through a Dispatch interface.
For example:
Code: [Select]
Object ob = Repository.GetElementByID(13);
if ( ob.ObjectType == otElement )
;
else if( ob.ObjectType == otAuthor )
"

I can't seem to get this to work properly... here's what I've tried in C#
The only Object class is a C# Object and that, of course, doesn't have ObjectType... there doesn't appear to be an EA.Object - the object model appears flat?

if I follow the API and do this:
EA.Element e = Repository.GetElementByID(13);
and if object 13 happens to be a Package,
then this doesn't seem to work
if (e.ObjectType == otPackage), seems the objectType is always otElement,
however, this appears to work:
if (e.Type == @"Package")
while I can go off and do this, is just doesn't "feel" right - what am I missing?

Also, what I'm really trying to do is walk the tree view and dispatch various element types to their own "print" or detail routines... most, but not all, elements have elements collections, diagram collections and package collections (among some others)... however, it doesn't seem that I can use some abstract superclass to cast my elements so that I can just get {superClass}.Diagrams for example, you have to Package.Diagrams or Element.Diagrams, which is why I think I need to determine the type of object I'm dealing with to cast it and then process collections.  Thinking that would lend itself to a nice recursive method to walk the tree, dispatching the "print" or detailed part of any element appropriately.

Any ideas?

thanks - cwt

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: object types
« Reply #1 on: February 26, 2010, 10:09:24 am »
GetElementByID will always return an otElement.
GetPackageByID will always return otPackage.

Functions that get current context or similar things can return one of the different types.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: object types
« Reply #2 on: February 26, 2010, 06:54:13 pm »
Chris,

Keep in mind that a package (except for root packages  :-/) also has a related Element.
This might be useful when recursively traversing a tree.

When I write tools on EA I never use the EA elements directly. I create wrappers that follow my own view on things (like how they inherit from each other).
This allows a lot more freedom in how to structure your design.

I've documented this as a pattern on http://themodelfactory.org/Pattern:Modelling_Tooling_Framework

Geert