0

使用最新的 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

这个过程有什么问题吗?

4

1 回答 1

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

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

注意: 此代码针对 BimServer 1.5.111 和 ifc2x3 进行了测试

此外,IfcBuildingStorey 是楼层或级别,IfcRelContainedInSpatialStructure 就像一些探测器,因此您可以根据需要进行修改。

于 2018-11-14T18:22:45.607 回答