(self)
| 244 | self.db.close() |
| 245 | |
| 246 | def create_geometry(self) -> None: |
| 247 | self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file) |
| 248 | |
| 249 | self.shape_rows = {} |
| 250 | self.geometry_rows = {} |
| 251 | |
| 252 | if self.file.schema in ("IFC2X3", "IFC4"): |
| 253 | elements = self.file.by_type("IfcElement") + self.file.by_type("IfcProxy") |
| 254 | else: |
| 255 | elements = self.file.by_type("IfcElement") |
| 256 | |
| 257 | self.settings = ifcopenshell.geom.settings() |
| 258 | self.settings.set("apply-default-materials", False) |
| 259 | |
| 260 | body_contexts = [ |
| 261 | c.id() |
| 262 | for c in self.file.by_type("IfcGeometricRepresentationSubContext") |
| 263 | if c.ContextIdentifier in ["Body", "Facetation"] |
| 264 | ] |
| 265 | # Ideally, all representations should be in a subcontext, but some BIM programs don't do this correctly |
| 266 | body_contexts.extend( |
| 267 | [ |
| 268 | c.id() |
| 269 | for c in self.file.by_type("IfcGeometricRepresentationContext", include_subtypes=False) |
| 270 | if c.ContextType == "Model" |
| 271 | ] |
| 272 | ) |
| 273 | self.settings.set("context-ids", body_contexts) |
| 274 | |
| 275 | products = elements |
| 276 | iterator = ifcopenshell.geom.iterator(self.settings, self.file, multiprocessing.cpu_count(), include=products) |
| 277 | valid_file = iterator.initialize() |
| 278 | if not valid_file: |
| 279 | # If there were no elements, iterator will also fail and it's okay not to report it. |
| 280 | if products: |
| 281 | print("WARNING. Geometry iterator failed to initialize.") |
| 282 | return |
| 283 | checkpoint = time.time() |
| 284 | progress = 0 |
| 285 | total = len(products) |
| 286 | while True: |
| 287 | progress += 1 |
| 288 | if progress % 250 == 0: |
| 289 | percent_created = round(progress / total * 100) |
| 290 | percent_preprocessed = iterator.progress() |
| 291 | percent_average = (percent_created + percent_preprocessed) / 2 |
| 292 | print( |
| 293 | "{} / {} ({}% created, {}% preprocessed) elements processed in {:.2f}s ...".format( |
| 294 | progress, total, percent_created, percent_preprocessed, time.time() - checkpoint |
| 295 | ) |
| 296 | ) |
| 297 | checkpoint = time.time() |
| 298 | shape = iterator.get() |
| 299 | if shape: |
| 300 | assert isinstance(shape, W.TriangulationElement) |
| 301 | shape_id = shape.id |
| 302 | geometry = shape.geometry |
| 303 | geometry_id = geometry.id |
no test coverage detected