Explode components in the IFC up to a certain level

Dear members,

I am relatively new to Ruby programming and I would like to ask a question related to my recent research about handling the IFC import for building analysis purposes (see below).

IFC is imported as several nested components and I would like to explode these components up to a certain hierarchical level. I was thinking the easiest way would be to search them by name, like “if i.name =~ /IfcStorey/” and then explode the components which have these names. But I am having hard time writing the code itself.

Any ideas / examples that I could use?


Be aware that in SketchUp, IFC (and any other classification) assignments are made at the component definition level.

:warning: This means that exploding any component instance(s) will lose all classification attributes, and any associated name property (either instance name or definition name.) This is because they just become loose geometry.

See this topic thread:

BUT, … IFC types are set in an attribute dictionary attached to the component’s definition.

So, if cinst was a reference to an IFC component instance, then you’d check the IFC type:

def ifc_type_is?( comp_inst, ifc_tag )
  dict = comp_inst.definition.attribute_dictionary("AppliedSchemaTypes")
  return false if dict.nil? # nil if it doesn't exist
  return dict["IFC 2x3"] == ifc_tag ? true : false

then call that method:

cinst.explode if ifc_type_is?(cinst,"IfcBuildingStorey")

Or like:

model.definitions.each {|cdef|
  dict = cdef.attribute_dictionary("AppliedSchemaTypes")
  if dict != nil && dict["IFC 2x3"] == "IfcBuildingStorey"
    cdef.instances.each {|i| i.explode }

BTW, I do not see “IfcStorey” as a tag in the “IFC 2x3” schema.
EDIT: Okay, changed examples above to “IfcBuildingStorey”.

Hello, Dan, thank you for your anwer! I will try to experiment with the code you shared.
I meant “IFCBUILDINGSTOREY” as a class to be precise.

1 Like

Okay I changed the above examples to use the correct IFC classification.