BBIM | Jupyter Notebook and Pandas like Spreadsheet Import/Export (for noobies)

These days I am using the Spreadsheet import/export feature in BBIM quite often since it provides a detailed output of an IFC model.
One thing I noticed was that, at the moment, there is no selector syntax to capture the name of elements grouped in an Assembly, so I asked Mr. ChatGPT 3.5 if I can sort this out differently.

I have extremely basic programming knowledge but I am bit familiar with Jupyter Notebook and Python Pandas to handle dataset (dataframes) and I thought I could give it a try, here is the result, quite good actually:

  1. load the libraries and model (I opened Jupyter Notebook from the same folder)
import ifcopenshell
import pandas as pd
file_path = '374 TechBuildPassingLoop 8.ifc'
ifc_file = ifcopenshell.open(file_path)
  1. select entities (IfcWall) and their aggregating relationship, create an empty list to store the output data
ifc_walls = ifc_file.by_type('IfcWall')
ifc_rel_aggregates = ifc_file.by_type('IfcRelAggregates')
data = []
  1. cycle through ifc_wall entities (matching predefined_type = STANDARD), appending collected info in the data list
for wall in ifc_walls:
    if hasattr(wall, 'PredefinedType') and wall.PredefinedType == 'STANDARD':
        wall_name = wall.Name if wall.Name else "Unnamed"
        wall_predefined_type = wall.PredefinedType if hasattr(wall, 'PredefinedType') else "Not Defined"
        aggregators = []

        # Check for related objects through IfcRelAggregates
        for rel in ifc_rel_aggregates:
            if wall in rel.RelatedObjects:
                aggregators.append(rel.RelatingObject.Name if rel.RelatingObject.Name else rel.RelatingObject.is_a())

        # Add the wall and its aggregators to the data list
        data.append({
            'WallName': wall_name,
            'PredefinedType': wall_predefined_type,
            'Assembly': ', '.join(aggregators) if aggregators else "None"
        })
  1. create a dataframe (table) using the data list
df = pd.DataFrame(data, columns=['WallName', 'PredefinedType', 'Assembly'])
  1. display the dataframe
with pd.option_context('display.max_rows', None,):
   print(df)

this is the output in JN

bonus

  1. you can export the dataframe to a .csv file as you would with the Spreadsheet Import/Export inside BBIM
csv_file_path = 'walls_with_aggregators.csv'
df.to_csv(csv_file_path, index=False)

final thoughts

A noticeable advantage of this procedure is that it can be performed straight from the IFC file without opening BBIM, once you go through basic python concepts it's not too difficult to operate with resulting data, like merging (joining) different datasets based on common key for instance.

I attach the Jupyter Notebook file (change the .txt suffix to .ipynb ) if interested

happy modeling.. and data digging :)

PS there are plenty of videos on YouTube showing how to install Jupyter Notebook on your computer, it's very easy but there are other online options (Google) as well

RoelemiliotassoMassimoAndrej730NigeltheoryshawOwura_qu
Sign In or Register to comment.