BoundingBox issues

edited September 2023 in General

Hi everyone,
I am trying to get bounding box dimensions of elements in my IFC files. I use the following code to achieve this:

def get_bbox_local(file, entity): 
    settings = ifcopenshell.geom.settings()
    elements = file.by_type(entity)
    for element in elements:
        shape = ifcopenshell.geom.create_shape(settings, element)
        geometry = shape.geometry  
        vertices = get_vertices(geometry)
        bbox = get_bbox(vertices)
        min_coords, max_coords = bbox

        # Extract individual min and max values for x, y, z
        minx, miny, minz = min_coords
        maxx, maxy, maxz = max_coords

        # Calculate dimensions
        length_x = maxx - minx
        width_y = maxy - miny
        height_z = maxz - minz

        # Store into DataFrame
        data = {
            'Length_X': [length_x],
            'Width_Y': [width_y],
            'Height_Z': [height_z]
        }

        df = pd.DataFrame(data)
        print(df)

Unfortunately for some reason objetcs not parallel to XYZ global coordinates get wrong dimensions. This is however happening incosistently - e.g. IfcDoors and IfcWalls always turn out correct, but IfcSlabs and IfcBeams don't. Does anyone have any idea how this could be solved?

Sign In or Register to comment.