Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create tree
- settings = ifcopenshell.geom.settings()
- context = ifcopenshell.util.representation.get_context(
- model, "Model", "Body", "MODEL_VIEW"
- )
- settings.set_context_ids([context.id()])
- iterator = ifcopenshell.geom.iterator(
- settings,
- model,
- multiprocessing.cpu_count(),
- include=model.by_type("IfcElement"),
- )
- if iterator.initialize():
- while True:
- # Use triangulation to build a BVH tree
- # tree.add_element(iterator.get())
- # Alternatively, use this code to build an unbalanced binary tree
- tree.add_element(iterator.get_native())
- if not iterator.next():
- break
- # Create clashes
- counter = 0
- for b in model.by_type("IfcElement"):
- print("----------------------------")
- print("Number of elements left: ", len(model.by_type("IfcElement")) - counter)
- print(f"That's the {counter+1}. element")
- print("Element investigated: ", b.Name)
- print("The element type is: ", b.is_a())
- print("-------")
- print("Start looking for clashed elements")
- print(" ")
- tic = time.perf_counter()
- elements = tree.select((b), extend=0.1)
- toc = time.perf_counter()
- print(f"Found {len(elements)} elements in: {toc - tic:0.4f} seconds")
- for b in model.by_type("IfcElement"):
- starting_guid = ifcopenshell.guid.expand(b.GlobalId)
- output += (
- "inst:Component_"
- + str(ifcopenshell.util.element.get_predefined_type(b)).lower()
- + "_"
- + str(b.id())
- + "\n"
- )
- output += "\ta brot:Component ;" + "\n"
- starting_guid = ifcopenshell.guid.expand(b.GlobalId)
- if b.Name:
- output += '\trdfs:label "' + b.Name + '"^^xsd:string ;' + "\n"
- if b.Description:
- output += '\trdfs:comment "' + b.Description + '"^^xsd:string ;' + "\n"
- if b.is_a():
- output += '\trdfs:type "' + b.is_a() + '"^^xsd:string ;' + "\n"
- for b in elements: # With looping through trees for each element I am able to get all adjacent # components. I intend to do the same but with results from clashes.
- if ifcopenshell.guid.expand(b.GlobalId) != starting_guid:
- output += (
- "\tbrot:adjacentComponent inst:component_"
- + b.Name
- + +ifcopenshell.util.element.get_predefined_type(b)
- + "_"
- + str(b.id())
- + "\n"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement