xBimTeam / XbimExchange

XbimExchange contains several COBie schemas and serialisation functions as well as the Model Validation library adopted by theNBS digital toolkit.
https://xbimteam.github.io/
Other
46 stars 42 forks source link

How to extract JSON with quantities #46

Open BrunoMBuzzi opened 4 years ago

BrunoMBuzzi commented 4 years ago

Hello there,

After researching for the pastcouple days, I've figure it out it would be better if I seek for your help here...

I've got to the point where I've implemented a solution similar to this one. https://github.com/xBimTeam/XbimEssentials/issues/94#issuecomment-313386981

But then, after creating the JSON, it seems there's no quantity data at all on this file. Is there any way I could create this JSON with more data on the elements? If yes, how could I do that, please?

Thanks, Bruno.

andyward commented 4 years ago

Can you share what you expect? What 'quantity data' did you want to see. (There's lots of ways of conveying quantities in a model)

BrunoMBuzzi commented 4 years ago

Hello @andyward ,

I would like to know if there's a way to extract the JSON with the exchanger including more data on each element, like material, properties and quantities.

I would like to get the same data that is shown in the Xbim Xplorer, but in JSON.

image

Thanks, Bruno

andyward commented 4 years ago

How are you extracting the JSON? Are you using COBieLiteUK Exchanger or something else?

If you are, it should be outputting quantities. i.e. this code

https://github.com/xBimTeam/XbimExchange/blob/261d31c95c736158a7289a3c9e0e5762ad464695/Xbim.Exchanger/IfcToCOBieLiteUK/XbimAttributedObject.cs#L452

If it's not can you provide a repo with:

1) The IFC model 2) The code you're using to generate the JSON

Worth noting that as a simpler schema, the JSON representation is always going to be a lossy version of the IFC, so not everything will make it through the exchange. I can't remember off hand if materials make the cut, but quantities should.

BrunoMBuzzi commented 4 years ago

I was using this code:

var facilities = new List<Facility>();
var exchanger= new IfcToCOBieLiteUkExchanger(model, facilities);
facilities = exchanger.Convert();

//there might be more than one facilities in theory but 
//COBie is only designed to hold a single building in a file.
for(var i = 0; i < facilities.Count; i++)
{
    var facility = facilities[i];
    var file = $"facility_{i}.json";
    facility.WriteJson(file);
}

But in the converted JSON there was no quantity information on many elements. Even opening on a text editor and manually searching, there wasn't a single element with Volume, which is a quantity that is shown when I open the IFC on the Xbim Xplorer.

andyward commented 4 years ago

Can you provide a model? Are you expecting the Facility to have a volume, or are you looking for it on a Space?

dumitrugrl commented 4 years ago

The code above is throwing an exception when trying to generate the JSON for the attached IFC file.

The exception is:

Exception: Object reference not set to an instance of an object.,    at XbimExchanger.IfcToCOBieLiteUK.XbimAttributedObject.GetAttributeValue(IIfcPropertyBoundedValue ifcPropertyBoundedValue)
   at XbimExchanger.IfcToCOBieLiteUK.XbimAttributedObject.ConvertToAttributeType(IIfcProperty ifcProperty)
   at XbimExchanger.IfcToCOBieLiteUK.CoBieLiteUkHelper.GetAttributes(IIfcObjectDefinition ifcObjectDefinition)
   at XbimExchanger.IfcToCOBieLiteUK.MappingIfcBuildingToFacility.Mapping(IIfcBuilding ifcBuilding, Facility facility)
   at XbimExchanger.IfcToCOBieLiteUK.IfcToCOBieLiteUkExchanger.Convert()

The code is:

 using (var model = IfcStore.Open(sFilePathName))
{
      var facilities = new List<Facility>();
      var exchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
      facilities = exchanger.Convert();
      var jsonFilename = Path.ChangeExtension(sFilePathName, "json");

      for (var i = 0; i < facilities.Count; i++)
      {
            var facility = facilities[i];
            var file = $"{sFilePathName}_{i}.json";

            if (facilities.Count == 1)
                        file = $"{sFilePathName}.json";

            facility.WriteJson(file);
      }
}

There are only two IFCPROPERTYBOUNDEDVALUE lines inside the IFC:

    Line 58: #163= IFCPROPERTYBOUNDEDVALUE('RentalRatesInCategoryNow',$,$,$,$);
    Line 60: #171= IFCPROPERTYBOUNDEDVALUE('RentalRatesInCategoryFuture',$,$,$,$);

I gues it has to do with the lines below in the XbimAttributedObject.cs where the ifcValue is null:

private static AttributeValue GetAttributeValue(IIfcPropertyBoundedValue ifcPropertyBoundedValue)
{            
            var ifcValue = (IExpressValueType) ifcPropertyBoundedValue.LowerBoundValue ;

Can you, please, have a look at the attached file? Is there something wrong with it?

test02.zip

dumitrugrl commented 4 years ago

After checking for null inside the GetAttributeValue and returning null my input file broke the code at a different point.

There is a line inside the IFC file that holds a value that is too big for an Int32:

1935= IFCPROPERTYSINGLEVALUE('ObjectID',$,IFCINTEGER(2509674408000),$);

This throws exception @ \Xbim.Exchanger\IfcToCOBieLiteUK\XbimAttributedObject.cs:line 829:

return new IntegerAttributeValue { Value = Convert.ToInt32(ifcValue.Value) };