0

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("admin@bimserver.org", "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?

Dakson
  • 75
  • 1
  • 7
  • did you try debugging? what is the end result that you want? – Shubham Nov 12 '18 at 07:51
  • yes, bimserver does not load any classes, end result is a bimserver with classes loaded so I can process their information – Dakson Nov 14 '18 at 15:38
  • Your code does not show how you actually access the model to retrieve entities of a given class. Your issue may be similar to https://stackoverflow.com/questions/52246562/null-pointer-exception-while-retrieving-all-instances-of-a-class-with-the-bimser, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer. – hlg Nov 15 '18 at 09:13
  • exactly, it fails silently, Because I want stability I use the latest official release, but I cant get the model loaded correctly. Because the model does not have any classes loaded I am unable to process anything. I do not think anything from 1.5.xxx is useful for this problem since I am using 1.4 which has a different API – Dakson Nov 15 '18 at 10:56
  • as hlg pointed out, that is what i have mentioned in my answer all you need to is adapt the answer but to your version of bim server – Shubham Nov 15 '18 at 11:16
  • that is what my code above already represents – Dakson Nov 15 '18 at 14:28
  • Again: it is impossible to give you any hints, if you do not post the code of how you "get any class such as IFCSlab etc." and what exactly you refer to when you state that "there is nothing inside it" - I assume it is some empty list, but where does it come from? Please edit your question to include this information. – hlg Nov 19 '18 at 10:45

1 Answers1

0

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("admin@bimserver.org", "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.

Shubham
  • 997
  • 1
  • 9
  • 15
  • Before BIMServer broke for me because of the Plugin Changes, I used to use 1.5.101. The plugin changes killed stability for me thats why I moved to 1.4 which is the stable version but it has breaking API changes. Thats why I need a solution for 1.4 – Dakson Nov 15 '18 at 10:54