How to programmatically filter model objects, in a Tekla model, by Part Position? (Tekla API)

_config.yml

Suppose you have a Tekla model and you want to programmatically filter for parts with a revision mark of abc/1. How would you do that?

  1. One way would be to iterate through the entire model, check for items which match your condition (perhaps via a LINQ query).
  2. The second would be to use Tekla’s native filtering mechanisms, which seem to be FAST:

When I originally tried the code, I had a single Binary Filter expression for just the part Position Number. I made a fatal assumption: that Tekla would be smart enough to realise that given I want a part position number, I also wanted a part.

The API returned almost everything under the sun. And I had no idea why. The documentation is very poor. So then I added a second Binary filter expression - this time one for parts.

Given we have two “filters”, we need to add them into a filter collection, and then finally, when we search, we search by .GetObjectsByFilter(filterCollection).

Here is the code:

And this post serves as the documentation, that is missing.

Contact Tek1 to discuss your API needs.

Written on July 9, 2024