import os import sys from ifcopenshell import ifcopenshell, geom from topologicpy.Topology import Topology def trace(frame, event, arg): print("%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno)) return trace #sys.settrace(trace) def openfile(): return ifcopenshell.open("test_simple_space.ifc") def get_boundaries(ifc_file): ''' Returns the list of IfcBuildingElement in the ifc file''' swap_list = [] for ifc_building_element in ifc_file.by_type("IfcBuildingElement"): if not any( [ ifc_building_element.is_a(ifc_type) for ifc_type in ["IfcCovering", "IfcRoof", "IfcSlab", "IfcWall"] ] ): continue if ifc_building_element.Decomposes: continue swap_list.append(ifc_building_element) return swap_list def config_geom_settings(): settings = geom.settings() settings.set(settings.USE_BREP_DATA, True) settings.set(settings.USE_WORLD_COORDS, True) settings.set(settings.DISABLE_TRIANGULATION, True) return settings def get_valid_ifcproducts(ifc_product): if ifc_product.Representation is not None: return ifc_product else: for ifc_rell_aggregates in ifc_product.IsDecomposedBy: for related_object in ifc_rell_aggregates.RelatedObjects: return get_valid_ifcproducts(related_object) def get_brepstring(ifc_product, settings): ''' Returns the BrepString of an IfcProduct''' ifc_product_shape = geom.create_shape(settings, ifc_product) brepstring = ifc_product_shape.geometry.brep_data return brepstring def process_each_brp(string): topology = Topology.ByBREPString(string) return topology #execution ifc_file = openfile() boundaries_list = get_boundaries(ifc_file) settings = config_geom_settings() valid_ifcproducts_list = [] get_brep_rep_list = [] topologies_list = [] for ifc_product in boundaries_list: valid_ifcproducts_list.append(get_valid_ifcproducts(ifc_product)) print(f'Found {len(valid_ifcproducts_list)} valid building items') for ifc_product in valid_ifcproducts_list: get_brep_rep_list.append(get_brepstring(ifc_product, settings)) print(f'Created {len(get_brep_rep_list)} brep strings') for brep_string in get_brep_rep_list: topo = process_each_brp(brep_string) topologies_list.append(topo) print(f'Created {len(topologies_list)} topologies by brepstrings')