IFC SDK supports the Standard Data Access Interface (SDAI) which provides a low-level API for manipulating data defined with the EXPRESS Schema and provides the following functionality:
- Sessions, repositories, models, and schema instance management.
- Manipulations with application data (entity instances, aggregates, attributes), including data validation.
SDAI is defined in the ISO 10303-22 standard.
This article describes, in general, how to work with SDAI in IFC SDK.
Prepare the environment and load a model from file
Open a file and create a model. First create a new session using sdaiOpenSession:
SdaiSession session = sdaiOpenSession();
The next step is repository initialization. In the created session, create a repository from a file. For this example, we use a sample file and open it:
_sdaiCreateRepositoryFromFile(session, sdaiPathToFileDirectory, nameRepo);
Here we use _sdaiCreateRepositoryFromFile. This function starts with the “_” symbol, which means this function is an ODA utility function that is not described in the specification.
If we pass a valid path to the file repository, it should be successfully created. Then we should open it using sdaiOpenRepository:
repoCreate = sdaiOpenRepository(session, repoCreate);
Now we can get a model from the open repository by name. The name of the file model is “default”. We should use sdaiAccessModelBN to do it:
SdaiModel model = sdaiAccessModelBN(repoCreate, modelName, accessMode);
If we don’t need the model anymore, we can close it using the function sdaiEndModelAccess. After that all read and write operations fail.
Access application instances
Our model is open in read-only mode and ready to use.
First, we should know how to access application instances. Let’s view the sample file as plain text and open it in a text editor:
ISO-10303-21; HEADER; FILE_DESCRIPTION(('ViewDefinition [DesignTransferView_V1.0]'),'2;1'); FILE_NAME('001-00','2019-01-14T10:55:12',(''),(''),'The EXPRESS Data Manager Version 5.02.0100.07 : 28 Aug 2013','20180806_1515(x64) - Exporter 184.108.40.206 - Alternate UI 220.127.116.11',''); FILE_SCHEMA(('IFC4')); ENDSEC; DATA; #1= IFCORGANIZATION($,'Autodesk Revit 2019 (ENU)',$,$,$); #5= IFCAPPLICATION(#1,'2019','Autodesk Revit 2019 (ENU)','Revit'); #6= IFCCARTESIANPOINT((0.,0.,0.)); … ENDSEC; END-ISO-10303-21;
For simple analysis, each string in the DATA section becomes an application instance of a model. The number is a handle of this instance. The instance type in upper case is placed after the equal symbol. The data in the round brackets is a parameter of this application instance. SdaiAppInstance is an SDAI data type for working with application instances.
Let’s read application instance #5. Look at the appInstanceAccessByHandle function in the sample code.
sdaiGetEntityById reads the application model from the model by its handle ID. We use the macro TEST_ASSERT for application instance validation. Then we call sdaiErrorQuery for the check error code of the last operation. We need to make sure that all operations are completed successfully:
//#5 = IFCAPPLICATION(#1, '2019', 'Autodesk Revit 2019 (ENU)', 'Revit'); SdaiAppInstance applicationInstance = _sdaiGetEntityById(model, 5); TEST_ASSERT(applicationInstance != NULL); TEST_ASSERT(sdaiErrorQuery() == sdaiNO_ERR);
We can check the type of application instance using the function sdaiIsInstanceOfBN.
TEST_ASSERT(sdaiIsInstanceOfBN(applicationInstance, "IFCAPPLICATION") == sdaiTRUE);
And then get a handle of the application instance and compare it with the handle that is being used with _sdaiGetEntityById:
TEST_ASSERT(_sdaiGetEntityId(applicationInstance) == 5); TEST_ASSERT(sdaiErrorQuery() == sdaiNO_ERR);
Finish and clean up the environment
When you finish working with the session, close the repository:
Then close the session:
Future blog articles will describe how to work with SDAI in more detail.