Closed soniagagliardi closed 7 years ago
Please make sure you open the model with XbimDBAccess.Exclusive
var model = GetXbimModel(filePath, xbimDatabase, true);
model.Open(xbimDatabase, XbimDBAccess.Exclusive);
private void SaveAsJson(string filePath, XbimModel model)
{
FileStream stream = null;
try
{
var cobieFileName = Path.ChangeExtension(filePath, "json");
stream = new FileStream(cobieFileName, FileMode.Create);
var helper = new CoBieLiteHelper(model);
var facility = helper.GetFacilities().FirstOrDefault();
if (facility != null)
{
using (var writer = new StreamWriter(stream))
{
CoBieLiteHelper.WriteJson(writer, facility);
writer.Close();
}
}
}
catch (Exception exception)
{
_logger.Error(exception);
}
finally
{
stream?.Dispose();
}
}
Hi,
Thank you for your reply. I followed your suggestion but still does not work completely. The method GetXbimModel(filePath, xbimDatabase, true) as it is defined? Maybe the problem is right there. I create the model as:
var model = new XbimModel(); model.CreateFrom(file.ifc, null, null, true); model.Open(file.xbim, XbimDBAccess.Exclusive); SaveAsJson(file.ifc, model);
where is my mistake?
CreateFrom call is wrong...
You have to do something like this:
private static XbimModel GetXbimModel(string inFileName, string xbimDb, bool caching)
{
var model = new XbimModel();
model.CreateFrom(
inFileName,
xbimDb,
null, false, caching
);
return model;
}
private static string GetXbimDatabase(string file, string extension)
{
return Path.ChangeExtension(file, extension);
}
inFileName is the IFC file name and xbimDb is a XbimDb that you have to create by calling the method below
var xbimDatabase = GetXbimDatabase(filePath, ".xbim");
var model = GetXbimModel(filePath, xbimDatabase, true);
model.Open(xbimDatabase, XbimDBAccess.Exclusive);
And then use the method SaveAsJson from previous comment.
The method SaveAsJson does not work at all. Does not display all the characteristics of the model.
The method that I wrote in the first post:
private void JsonFile(XbimModel model, string ifcmodelfile)
{
if (model != null)
{
var context = new Xbim3DModelContext(model);
context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary);
var wexBimFilename = Path.ChangeExtension(ifcModelFile, "wexBIM");
using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
{
using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
{
Console.WriteLine("Creating " + wexBimFilename);
context.Write(wexBimBinaryWriter);
wexBimBinaryWriter.Close();
}
wexBiMfile.Close();
}
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(ifcModelFile);
var fileDirectoryName = Path.GetDirectoryName(ifcModelFile);
List<Facility> facilities = new List<Facility>();
var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
if (ifcToCoBieLiteUkExchanger != null)
{
facilities = ifcToCoBieLiteUkExchanger.Convert();
var facilityNumber = 0;
foreach (var facility in facilities)
{
var dpow = "DPoW";
if (facilities.Count > 1)
dpow += ++facilityNumber;
var dPoWFile = Path.Combine(fileDirectoryName, fileNameWithoutExtension + "_" + dpow);
dPoWFile = Path.ChangeExtension(dPoWFile, "json");
facility.WriteJson(dPoWFile);
}
}
}
}
but It does not work with all IFC file and returns an exception in the class XbimExchanger.IfcToCOBieLiteUK.MappingIfcBuildingToFacility like this:
facility.Attributes is null but facility.Site is not null.
I hope I was understandable enough
I had the same issue with one of the IFC files where it comes to be null but I have no clue why that would be.
var facility = helper.GetFacilities().FirstOrDefault();
Facility comes out to be null and I think you having the same issue.
while this method you have ever used?
Not sure what you mean
Have you ever used the method JsonFile the comment Previous?
Please see the Pas1192 example in the Exchange project on the Develop Branch for correct usage
Hi,
I have converted my IFC Model to .wexbim and .xbim but how can I create the expected .json file?
I used to generate the json file using Xbim.Exchange in this way:
but I have this error
What is the problem?
Thanks