I am very new to BIMserver and I am trying to get instances of a specific class of the IFC I have checked in, using the Java client library and IfcModelInterface.
Here is the piece of code :
IfcModelInterface model = client.getModel(project, project.getLastRevisionId(),false, true,true);
Collection<IfcProduct> products = model.getAllWithSubTypes(IfcProduct.class);
The call to getAllWithSubtypes
results in a null pointer exception.
When I debug it goes to the class where :
public <T extends IdEObject> List<T> getAllWithSubTypes(EClass eClass) {
if (!loadedClasses.contains(eClass.getName()) && modelState != ModelState.FULLY_LOADED) {
eClass is null and hence I get an exception, I don't understand why?
Looking at your stacktrace, I assume this line is Connecting.java:48
This calls the following method (IfcModel.java:310)
And then we come to the NullPointer when
eClass.getName()
is called in (ClientIfcModel.java:582)You pass in an ordinary Java
Class interfaceClass
which gets mapped into an EMFEClass
in order to retrieve all its instances. This mapping is carried out inpackageMetaData.getEClass(interfaceClass)
. It only works if theClass interfaceClass
that you pass in pertains to the same IFC schema version as the model'spackageMetaData
.For instance, let's say your requested interfaceClass is
org.bimserver.models.ifc4.IfcProduct
and yourmodel.getPackageMetaData().getSchema()
isSchema.IFC2X3TC1
, then the mapping will return anEClass null
and you will subsequently see the NullPointer.To prevent the NullPointer exception, you would have to do a runtime check of the model's schema and only request the instances if the schema is what you expect.