MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / create_geometry

Method create_geometry

src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py:246–335  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers 1

patchMethod · 0.95

Calls 14

add_geometry_rowMethod · 0.95
printFunction · 0.85
calculate_unit_scaleMethod · 0.80
formatMethod · 0.80
by_typeMethod · 0.45
setMethod · 0.45
idMethod · 0.45
extendMethod · 0.45
iteratorMethod · 0.45
initializeMethod · 0.45
getMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected