Book a Demo

Author Topic: Finding an element by name  (Read 5128 times)

Ricardo Guerra

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Finding an element by name
« on: February 28, 2009, 04:24:42 am »
Hi there,

i need to find an element in the model and i only know its name.
I'm using the EA.Package.FindObject(myObjectName) but it throws an exception stating "Can´t find matching object".

Thanks in advance!

Cheers,
Ricardo

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Finding an element by name
« Reply #1 on: March 02, 2009, 11:59:31 am »
The FindObject() method requires a dotted path to the element in relation to the current package.  E.g. "System.Class1".  If you only know the name of the object, but do not know which package it is contained in, you might try using Repository.GetElementsByQuery() instead.  This allows you to execute an EA model search and returns the results as a Collection.

Example:
  Dim results As EA.Collection
  Set results = Repository.GetElementsByQuery("Simple", "Class1")

Ricardo Guerra

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Finding an element by name
« Reply #2 on: March 03, 2009, 04:39:00 am »
Thanks for your reply Aaron!

I managed to get element ids now so it became easier to get elements.
Your approach forces me to have the queries pre-created in EA.

Cheers,
Ricardo