Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extract JSON with quantities #46

Open
BrunoMBuzzi opened this issue Jul 23, 2019 · 7 comments
Open

How to extract JSON with quantities #46

BrunoMBuzzi opened this issue Jul 23, 2019 · 7 comments
Assignees

Comments

@BrunoMBuzzi
Copy link

BrunoMBuzzi commented Jul 23, 2019

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.
xBimTeam/XbimEssentials#94 (comment)

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

internal static TCoBieValueBaseType ConvertAttribute<TCoBieValueBaseType>(IIfcPhysicalQuantity ifcQuantity) where TCoBieValueBaseType : AttributeValue, new()

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
Copy link
Author

BrunoMBuzzi commented Jul 25, 2019

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
Copy link
Member

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

@dumitrugrl
Copy link

dumitrugrl commented Aug 30, 2019

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

@andyward andyward self-assigned this Aug 30, 2019
@dumitrugrl
Copy link

dumitrugrl commented Sep 2, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants