BimServer 1.4 getModel always returns an empty model

250 views Asked by At

Using the latest BIMServer 1.4.0 I am unable to load my model. The model is returned, but it does not contain any classes. The lifecycle of the ifc:

I initialize like this

        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        pluginManager.loadPluginsFromCurrentClassloader();
        // Create a MetaDataManager, and initialize it, this code will be simplified/hidden in the future
        MetaDataManager metaDataManager = new MetaDataManager(pluginManager);
        pluginManager.setMetaDataManager(metaDataManager);
        metaDataManager.init();

        // Initialize all loaded plugins
        pluginManager.initAllLoadedPlugins();

        // Create a factory for BimServerClients, connnect via JSON in this case
        BimServerClientFactory factory = new JsonBimServerClientFactory(metaDataManager, "http://localhost:8082");

        // Create a new client, with given authorization, replace this with your credentials
        BimServerClientInterface client = factory.create(new UsernamePasswordAuthenticationInfo("[email protected]", "none"));
        setup(client);

checkin via bimviews gui (IFC2x3 Step deserializer) using this code I try to get the model

  List<SProject> project = client.getBimsie1ServiceInterface().getProjectsByName("BIM");
        SProject newProject = client.getBimsie1ServiceInterface().getProjectByPoid(project.get(0).getOid());

        return client.getModel(newProject, newProject.getLastRevisionId(), true, false, true);

getting any class such as IFCSlab etc. proves to be unsuccesful because there is nothing inside it I tried visualizing it in bimviews and it works there.

A sample IFC: http://www.mediafire.com/file/8i8v7kfcou3ok2c/IFC_%25C3%2596ffnungen.ifc/file

Is there something wrong with this process?

1

There are 1 answers

1
Shubham On

can you try above code?

import java.util.ArrayList;
import java.util.List;
import org.bimserver.client.BimServerClient;
import org.bimserver.client.json.JsonBimServerClientFactory;
import org.bimserver.emf.IfcModelInterface;
import org.bimserver.interfaces.objects.SProject;
import org.bimserver.models.ifc2x3tc1.IfcBuildingStorey;
import org.bimserver.models.ifc2x3tc1.IfcDistributionControlElement;
import org.bimserver.models.ifc2x3tc1.IfcObject;
import org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure;
import org.bimserver.shared.ChannelConnectionException;
import org.bimserver.shared.UsernamePasswordAuthenticationInfo;
import org.bimserver.shared.exceptions.BimServerClientException;
import org.bimserver.shared.exceptions.ServerException;
import org.bimserver.shared.exceptions.ServiceException;
import org.bimserver.shared.exceptions.UserException;
import org.bimserver.shared.interfaces.ServiceInterface;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Connecting {
List<String> names = new ArrayList<String>();
@GetMapping("/BimServerConnection")
@ResponseBody
public List<String> bimConnection() {
    try {
        BimServerClient client = isBimServerConnected();
        List<SProject> projects = getAllSProjects(client);
        names = extractIfcObject(client, projects);
    } catch (BimServerClientException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ChannelConnectionException e) {
        e.printStackTrace();
    }
    return names;
}

private static BimServerClient isBimServerConnected()
        throws BimServerClientException, ServiceException, ChannelConnectionException {
    JsonBimServerClientFactory factory = new JsonBimServerClientFactory("http://localhost:8082");
    BimServerClient client = factory.create(new UsernamePasswordAuthenticationInfo("[email protected]", "admin"));
    if (client.isConnected()) {
        System.out.println("Connected");
    }
    return client;
}

private static List<SProject> getAllSProjects(BimServerClient client) throws ServerException, UserException {
    ServiceInterface serviceInterface = client.getServiceInterface();
    List<SProject> projects = serviceInterface.getAllWritableProjects();
    return projects;
}

private static List<String> extractIfcObject(BimServerClient client, List<SProject> projects)
        throws UserException, ServerException {
    List<String> detectorNames = new ArrayList<String>();
    for (SProject project : projects) {
        if (project.getName().equals("WestRiverSideHospitalFireAlarm_1.ifc")) {
            IfcModelInterface model = client.getModel(project, project.getLastRevisionId(), false, true, true);
            List<IfcBuildingStorey> controller = new ArrayList<IfcBuildingStorey>();
            controller.addAll(model.getAllWithSubTypes(IfcBuildingStorey.class));
            List<IfcRelContainedInSpatialStructure> spatialStructure = new ArrayList<IfcRelContainedInSpatialStructure>();
            for (IfcBuildingStorey control : controller) {
                if(control.getName().equals("Level 5")) {
                    System.out.println(control.getName());
                    spatialStructure.addAll(control.getContainsElements());
                }
            }
            List<IfcObject> relatedElements = new ArrayList<IfcObject>();
            for (IfcRelContainedInSpatialStructure spl : spatialStructure) {
                    relatedElements.addAll(spl.getRelatedElements());
            }
            System.out.println("All Devices");
            for (IfcObject ifc : relatedElements) {
                if (ifc instanceof IfcDistributionControlElement) {
                    System.out.println(ifc.getName());
                    detectorNames.add(ifc.getName());
                }
            }
        }
    }
    return detectorNames;
}
}

I intentionally gave the import statements as you need to be specific for the type of ifc format you are checking in that is ifc2x3 or ifc4. This is my code that i used it works fine for me, just use the rest end point. just replace the name of the project. Do let me know the output. you can extract the information as per your needs.

Note: This code is tested against BimServer 1.5.111 and ifc2x3

Also, IfcBuildingStorey is the floors or the levels and IfcRelContainedInSpatialStructure are like some detectors so you can modify as per your need.