Author Topic: Accessing Models through Interop and getting documentation or examples for C#  (Read 334 times)

vsantos01

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Hi,

I'm starting to develop a C# console application to interact with my .eapx file. I'm at the very beggining and I have been able so far to open the file and get a reference to the model by using repo.Models.GetAt(0). The variable referring to this model, though, is of type object and thus does not have any field or method related to the model itself.

Code: [Select]
var repository = new EA.Repository();
repository.OpenFile("c:\tmp\myeap.eapx");
var model = repository.Models.GetAt(0);      // --> Here, model ends up being of "object" type

I have seen in the page https://sparxsystems.com/enterprise_architect_user_guide/14.0/automation/iteratethroughaneapfile.html that models contain elements such as the Name or the Packages, but if I try to use them, C# compiler complains as both Name and Packages are not properties of object type.

How can I access the data contained in a model?
Is there a place with the complete documentation of the Interop API and/or examples in C#?

Thanks!
Victor

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 12048
  • Karma: +469/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
The manual contains a complete reference to the API:
https://sparxsystems.com/enterprise_architect_user_guide/16.0/add-ins___scripting/reference.html

EA uses a lot of generic collections. All of these collections return objects of type "object".  Depending on where you are, you'll have to cast these to the type you need. (e.g. Repository.Models is a collection of EA.Package)

You can find a bunch of examples on my github repo's:

https://github.com/GeertBellekens/Enterprise-Architect-Toolpack

Geert