1

I am working on a project that requires parsing IFC files using xBim and I need support both Ifc2x3 and Ifc4. Most of the Ifc class names and their properties are same in Ifc2x3 and Ifc4, but in xBim's object model the same classes in Ifc2x3 and Ifc4 namespaces do not share a common base class or interface so I will have to write the same code twice. I mean, if I am writing a function that retreives the volume of the space, or something simple like that, I would have to write that once for Ifc2x3 version of IfcSpace and another time for Ifc4 version of IfcSpace.

I thought about using compile-time directives to decide which namespace to load, but I am not sure if that is a good idea. I know this is an odd request, but is there any other way I can avoid writing the same code twice ?

1 Answers1

1

You should just be able to use the interfaces in the Xbim.Ifc4.Interfaces namespace. These interfaces are common across Ifc2x3 and Ifc4 implementations for precisely this scenario.

The sample at the bottom of the Xbim Quick Start demonstrates this scenario of working across Ifc Schemas with a single code base. http://docs.xbim.net/quick-start.html

Andy Ward
  • 324
  • 2
  • 7
  • These interfaces don't seem to reconcile all the schema differences ? For example, IfcDirection.DirectionRatios is an IItemSet in Ifc2x3 and IItemSet in Ifc4. I assume there are lots of other differences like that, wouldn't that be a problem ? – Ranjeeth Mahankali Apr 14 '18 at 19:34
  • Also, would this work when creating Ifc data ? Can I instantiate these interfaces and later cast them to either Ifc2x3 or Ifc4 without schema conflicts ? – Ranjeeth Mahankali Apr 14 '18 at 19:40
  • I believe that when creating new entities you need to provide the correct type for the schema when using `store.Instances.New`. – Andy Ward Apr 16 '18 at 09:39
  • On the interface differences, the recommendation is to just use the Ifc4 interfaces to read data from both schema as it's essentially a superset of both Ifc schemas – Andy Ward Apr 16 '18 at 09:41
  • Hi, can you look at this question ? https://stackoverflow.com/questions/50339650/cannot-find-ifcproduct-transform-method-in-ifc4-namespace-xbim-essentials – Ranjeeth Mahankali May 14 '18 at 22:04