BimServer 1.4 getModel always returns an empty model
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?
ifc bim
|
show 2 more comments
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?
ifc bim
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7: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 stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9: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
|
show 2 more comments
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?
ifc bim
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?
ifc bim
ifc bim
asked Nov 8 '18 at 15:35
DaksonDakson
2016
2016
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7: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 stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9: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
|
show 2 more comments
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7: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 stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9: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
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7:51
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7: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
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 stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9:13
Your code does not show how you actually access the model to retrieve entities of a given class. Your issue may be similar to stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9: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
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
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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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.
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211077%2fbimserver-1-4-getmodel-always-returns-an-empty-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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.
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.
answered Nov 14 '18 at 18:22
ShubhamShubham
15219
15219
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
add a comment |
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
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
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
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211077%2fbimserver-1-4-getmodel-always-returns-an-empty-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did you try debugging? what is the end result that you want?
– Shubham
Nov 12 '18 at 7: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 stackoverflow.com/questions/52246562/…, just that in this older BIMserver version (which you are using) it fails silently instead of with a NullPointer.
– hlg
Nov 15 '18 at 9: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