ODA IFC SDK Developer's Guide > Standard Data Access Interface in IFC SDK > Work with Attributes > Work with Select Attributes
Work with Select Attributes

Select attributes can contain values of different types. To provide storage of different types of values with different lengths in bytes, the attribute data block (ADB) is used.

This topic shows how these attributes can be read.

It is assumed that there is an instance similar to the following in an .ifc file (with an attribute select value):


// #49 = IFCMEASUREWITHUNIT(IFCRATIOMEASURE(0.0174532925199433), #47);
    

It has a select attribute named "valuecomponent". To get access to its value and work with it, follow the routine below:

  1. Read the application instance by using the _sdaiGetEntityById() function call:
    
    SdaiAppInstance applicationInstance = _sdaiGetEntityById(model, 49);
    if ((applicationInstance == NULL) || (sdaiErrorQuery() != sdaiNO_ERR))
      return;
            
  2. To read a select attribute from an application instance, use, like other cases, the sdaiGetAttrBN() function. But for getting access to a select attribute, pass an already created ABD value as the fourth parameter to this function. To create a new ADB value, call the sdaiCreateEmptyADB() function:
    
    SdaiADB adbToGet = sdaiCreateEmptyADB();
    if (adbToGet != NULL)
    {
      if (sdaiGetAttrBN(applicationInstance, "valuecomponent", sdaiADB, &adbToGet ) == NULL)
        return;
    }
            
  3. Extract the value contained in the attribute data block. It is necessary to know the attribute data type to get the correct value from the ADB. When you successfully get it, you can try to extract a value contained at the ADB. As you can see from the fragment of the .ifc file above, the attribute data block stores a real value (IFCRATIOMEASURE(0.0174532925199433)), therefore you have to get the attribute value as a real data type value:
    
    SdaiReal  adbRealValue = .0;
    sdaiGetADBValue(adbToGet, sdaiREAL, &adbRealValue );
    if (!OdEqual(0.0174532925199433, adbRealValue))
      return;
            

    According to the code fragment, the sdaiGetADBValue() function should be called to get a value from an attribute data block. This function accepts three parameters:

    • A handle of the attribute data block.
    • An attribute data type.
    • A placeholder to store the value of the requested data type.

    The sdaiGetADBValue() function returns a raw pointer to the attribute value if it is successfully retrieved or the NULL value in the other case so you can check the result of the ADB operation.

    Another type of data that can be stored in an attribute data block is a path. The path contains an array of strings and can be obtained by the call of the sdaiGetADBTypePath function:

    
    SdaiInteger collectionSize = 0;
    SdaiString* pathCollection = sdaiGetADBTypePath(adbToGet, &collectionSize);
    
    if (collectionSize > 0)
    {
      for (SdaiInteger pathIndex = 0; pathIndex < collectionSize; ++pathIndex)
      {
        if (!pathCollection[pathIndex] || odStrLenA(pathCollection[pathIndex]) <= 0)
          return;
      }
    }
            

    The sdaiGetADBTypePath() function returns a raw pointer to a string array if successful or the NULL value in the other case.

  4. When the ADB instance is not necessary anymore, call the sdaiDeleteADB() function to delete it and free the memory:
    
    sdaiDeleteADB(adbToGet);
    if (sdaiErrorQuery() != sdaiNO_ERR)
      return;
            

See Also

Work with Aggregate Attributes

Work with Attributes

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.