Book a Demo

Author Topic: list of every elements  (Read 4319 times)

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
list of every elements
« on: March 31, 2010, 06:40:14 pm »
Hello,

I'd like to modify every elements by script. For that I need to find all the belements.
The example of EA tutorial shows how to obtain all the elements of the current Package; it's something like this :

Pack = Rep.GetTreeSelectedPackage();
foreach(Package myPack in Pack.Packages)
{
   foreach(Element myElem in Pack.Elements)
   {
   ...

but I want more, and want every elements in the project.
I have read in the EA help  that Model is the top level but I could use it efficiently (it is a Collection and than I could'nt extract all the Packages included in Model)

Do you know how to do ?

Thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: list of every elements
« Reply #1 on: March 31, 2010, 07:07:54 pm »
You can use
Code: [Select]
Repository.GetElementSet("select object_ID from t_object",2)
Geert

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: list of every elements
« Reply #2 on: March 31, 2010, 07:43:55 pm »
After Repository.GetElementSet("select object_ID from t_object",2)  you  have a Collection of Objects.
How do you extract them ?
I used GetAt(0) GetAt(1)... but I can't have the name or the Element ID, the only thing I have is System.__ComObject  when I use GetAt()
(but it is the only solution to use a GetAt isn't it ?)
« Last Edit: March 31, 2010, 07:45:20 pm by utilisateurEA »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: list of every elements
« Reply #3 on: March 31, 2010, 07:53:57 pm »
Yes, that is the lovely thing about the EA.Collection, it returns objects of type Object.
You have to cast them to EA.Element
so something like
Code: [Select]
EA.Element myElement = (EA.Element)myCollection.getAt(i)
Geert

utilisateurEA

  • EA User
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: list of every elements
« Reply #4 on: March 31, 2010, 08:03:39 pm »
Thank you !