【问题标题】:BimServer 1.4 getModel always returns an empty modelBimServer 1.4 getModel 总是返回一个空模型
【发布时间】:2018-11-08 15:35:39
【问题描述】:

使用最新的 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 Step deserializer) 使用此代码我尝试获取模型

  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

这个过程有什么问题吗?

【问题讨论】:

  • 你尝试调试了吗?你想要的最终结果是什么?
  • 是的,bimserver 不加载任何类,最终结果是一个加载了类的 bimserver,因此我可以处理它们的信息
  • 您的代码没有显示您如何实际访问模型以检索给定类的实体。您的问题可能类似于stackoverflow.com/questions/52246562/…,只是在这个较旧的 BIMserver 版本(您正在使用)中,它会静默失败,而不是使用 NullPointer。
  • 没错,它静默失败,因为我想要稳定我使用最新的官方版本,但我无法正确加载模型。因为模型没有加载任何类,所以我无法处理任何东西。我不认为 1.5.xxx 中的任何内容对这个问题有用,因为我使用的是具有不同 API 的 1.4
  • 正如 hlg 所指出的,这就是我在回答中提到的,您只需调整答案,但要适应您的 bim 服务器版本

标签: ifc bim


【解决方案1】:

你能试试上面的代码吗?

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 就像一些探测器,因此您可以根据需要进行修改。

【讨论】:

  • 在 BIMServer 因插件更改而中断之前,我曾经使用 1.5.101。插件更改对我来说杀死了稳定性,这就是为什么我迁移到 1.4,这是稳定版本,但它有破坏性的 API 更改。这就是为什么我需要 1.4 的解决方案
猜你喜欢
  • 1970-01-01
  • 2021-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多