Book a Demo

Author Topic: GetbyName  (Read 5901 times)

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
GetbyName
« on: July 29, 2015, 07:35:36 pm »
Hi,

I want to retrieve a specific test from the inside of an element.
As the API promises, it should be no big deal.

"element.Tests.GetByName(testname)"

However, it failes with

"System.Runtime.InteropServices.COMException (0x80040002): Action is not supported

   bei EA.IDualCollection.GetByName(String Name)"

Any idea?

Regards

Stefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: GetbyName
« Reply #1 on: July 29, 2015, 08:28:57 pm »
The documentation for Tests says
Quote
A collection of Test objects for the current element.
It does not tell that GetByName is supported. There are only some collections that actually support GetByName (IIRC TVs). Anyhow, as names are not unique you should implement your own wrapper to handle non-uniqueness.

q.

P.S. Doc for Collection:
Quote
Gets an item in the current collection by Name.

If the collection does not contain any items, the method returns a null value. If the collection contains items, but it was unable to find an object with the specified name, the method raises an exception.

Only supported for the following collections: Model, Package, Element, Diagram, and element TaggedValue.

Parameters:

· Name: String
  
« Last Edit: July 29, 2015, 08:30:48 pm by qwerty »

E.Eckstein

  • EA User
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Re: GetbyName
« Reply #2 on: August 04, 2015, 10:04:41 pm »
Hi there,

you might just use a small workaround which will work fine:
Just write your own method (like this one in C#)
Code: [Select]
private EA.Test MyGetByName(EA.Element myelement, string name)
{
  foreach(EA.Test test in myelement.Tests)
  {
    if(test.Name.Equals(name))
       return test;
  }
  return null;
}
« Last Edit: August 04, 2015, 10:06:04 pm by ericeckstein »