IFC SDK and SDAI: Work with Sets of Application Instances

Egor Vorobyov

January 28, 2021

IFC SDK supports the Standard Data Access Interface (SDAI) which provides a low-level API for manipulating data defined with the EXPRESS Schema. This article describes how to work with sets of application instances.

For details about generally working with SDAI in IFC SDK, see this article.

An .ifc file may contain several application instances of one type. For these cases, SDAI provides an interface that allows you to:

  • Search all instances of a specified type.
  • Manipulate a set of instances of one type, including sequential access to the elements of the set via an iterator object.

To get a set of application instances of a specific type, use the sdaiGetEntityExtentBN() function.

To check whether any instance of the specified type is found, call the sdaiGetMemberCount() function. This function returns the quantity of elements in a set.

When you have a non-empty set of instances, you can create an iterator object and then walk through the elements of the set using the following functions:

  • sdaiCreateIterator() — Create an iterator object (represented with the SdaiIterator datatype).
  • sdaiBeginning() — Move to the first element of the set.
  • sdaiNext() — Get access to the next element of the set.
  • sdaiGetAggrByIterator() — Get access to the current element of the set.

The following code fragments illustrate how to find all IFCBSPLINECURVEWITHKNOTS instances in a model and iterate through the set of found instances.

SdaiString entityName = "IFCBSPLINECURVEWITHKNOTS";
SdaiSet bsplineInstanceSet = sdaiGetEntityExtentBN(model, entityName);

Make sure the set of typed application instances is valid. The length of the set should not equal zero:

TEST_ASSERT(sdaiGetMemberCount(bsplineInstanceSet) > 0);

Then use an iterator to walk through all items of the aggregate:

SdaiIterator bsplineIterator = sdaiCreateIterator(bsplineInstanceSet);
TEST_ASSERT(sdaiErrorQuery() == sdaiNO_ERR);

for (sdaiBeginning(bsplineIterator); sdaiNext(bsplineIterator);)
 {
    SdaiInstance instance = NULL;
    sdaiGetAggrByIterator(bsplineIterator, sdaiINSTANCE, &instance);

    SdaiInteger instanceId = _sdaiGetEntityId(instance);

    TEST_ASSERT(sdaiErrorQuery() == sdaiNO_ERR);
 }