Advertisement
SirCamembert

clash sorting

Apr 17th, 2024
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1.     # Create tree
  2.     settings = ifcopenshell.geom.settings()
  3.     context = ifcopenshell.util.representation.get_context(
  4.         model, "Model", "Body", "MODEL_VIEW"
  5.     )
  6.     settings.set_context_ids([context.id()])
  7.     iterator = ifcopenshell.geom.iterator(
  8.         settings,
  9.         model,
  10.         multiprocessing.cpu_count(),
  11.         include=model.by_type("IfcElement"),
  12.     )
  13.     if iterator.initialize():
  14.         while True:
  15.             # Use triangulation to build a BVH tree
  16.             # tree.add_element(iterator.get())
  17.  
  18.             # Alternatively, use this code to build an unbalanced binary tree
  19.             tree.add_element(iterator.get_native())
  20.  
  21.             if not iterator.next():
  22.                 break
  23.  
  24.     # Create clashes
  25.     counter = 0
  26.     for b in model.by_type("IfcElement"):
  27.         print("----------------------------")
  28.         print("Number of elements left: ", len(model.by_type("IfcElement")) - counter)
  29.         print(f"That's the {counter+1}. element")
  30.         print("Element investigated: ", b.Name)
  31.         print("The element type is: ", b.is_a())
  32.         print("-------")
  33.         print("Start looking for clashed elements")
  34.         print("   ")
  35.         tic = time.perf_counter()
  36.         elements = tree.select((b), extend=0.1)
  37.         toc = time.perf_counter()
  38.         print(f"Found {len(elements)} elements in:  {toc - tic:0.4f} seconds")
  39.        
  40.  
  41.     for b in model.by_type("IfcElement"):
  42.         starting_guid = ifcopenshell.guid.expand(b.GlobalId)
  43.         output += (
  44.             "inst:Component_"
  45.             + str(ifcopenshell.util.element.get_predefined_type(b)).lower()
  46.             + "_"
  47.             + str(b.id())
  48.             + "\n"
  49.         )
  50.         output += "\ta brot:Component ;" + "\n"
  51.         starting_guid = ifcopenshell.guid.expand(b.GlobalId)
  52.         if b.Name:
  53.             output += '\trdfs:label "' + b.Name + '"^^xsd:string ;' + "\n"
  54.         if b.Description:
  55.             output += '\trdfs:comment "' + b.Description + '"^^xsd:string ;' + "\n"
  56.         if b.is_a():
  57.             output += '\trdfs:type "' + b.is_a() + '"^^xsd:string ;' + "\n"
  58.         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.
  59.             if ifcopenshell.guid.expand(b.GlobalId) != starting_guid:
  60.                 output += (
  61.                     "\tbrot:adjacentComponent inst:component_"
  62.                     + b.Name
  63.                     + +ifcopenshell.util.element.get_predefined_type(b)
  64.                     + "_"
  65.                     + str(b.id())
  66.                     + "\n"
  67.                 )
Tags: ifc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement