Book a Demo

Author Topic: Get instances of a component  (Read 2976 times)

Mike Pagel

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Get instances of a component
« on: August 23, 2012, 05:03:57 pm »
In an add-in, how do find all instances of a component (as Element). In EA this is shown in the traceability view, but I did not find an efficient programmatic way yet (other than experimenting with queries and SQL, or perform an expensive backwards search from all instances in the model...).

Any help is highly appreciated.

Mike

Mike Pagel

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Get instances of a component
« Reply #1 on: August 23, 2012, 07:48:55 pm »
Just thought I'd post the SQL based solution I came up with, which is much faster than the reverse search via automation-based model traversal:

Code: [Select]
public Collection GetInstances( Element classifier )
{
    string query = string.Format( "select * from t_object where Object_Type = \"{0}\" and Classifier_guid = \"{1}\";", classifier.Type, classifier.ElementGUID );
    return repository.GetElementSet( query, 2 );
}

Mike