BimServer 1.4 getModel始终返回空模型

时间:2018-11-08 15:35:39

标签: ifc bim

使用最新的BIMServer 1.4.0,我无法加载模型。 该模型被返回,但是它不包含任何类。 ifc的生命周期:

我这样初始化

        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);
通过bimviews gui 签入(IFC2x3步骤解串器) 使用此代码,我尝试获取模型

  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);

获取任何类(如IFCSlab等)被证明是不成功的,因为其中没有任何内容 我尝试在bimviews中将其可视化,并且在那里可以正常工作。

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

此过程有问题吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试上面的代码吗?

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;
}
}

我故意提供了import语句,因为您需要特定于要检查的ifc格式类型,即ifc2x3或ifc4。这是我使用的代码,对我来说效果很好,只需使用其余端点即可。 只需替换项目名称即可。让我知道输出。您可以根据需要提取信息。

注意: 此代码已针对BimServer 1.5.111和ifc2x3

进行了测试

此外,IfcBuildingStorey是楼层或楼层,IfcRelContainedInSpatialStructure类似于某些检测器,因此您可以根据需要进行修改。