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

Method insert_data

src/ifcpatch/ifcpatch/recipes/Ifc2Sql.py:546–624  ·  view source on GitHub ↗
(self, ifc_class: str)

Source from the content-addressed store, hash-verified

544 self.c.execute(statement)
545
546 def insert_data(self, ifc_class: str) -> None:
547 elements = self.file.by_type(ifc_class, include_subtypes=False)
548
549 rows: list[list[Any]] = []
550 id_map_rows: list[tuple[int, str]] = []
551 pset_rows: list[tuple[int, str, str, Any]] = []
552
553 for element in elements:
554 nested_indices: list[int] = []
555 values: list[Any] = [element.id()]
556 for i, attribute in enumerate(element):
557 if isinstance(attribute, ifcopenshell.entity_instance):
558 if attribute.id():
559 values.append(attribute.id())
560 else:
561 values.append(json.dumps({"type": attribute.is_a(), "value": attribute.wrappedValue}))
562 elif (
563 self.should_expand
564 and attribute
565 and isinstance(attribute, tuple)
566 and isinstance(attribute[0], ifcopenshell.entity_instance)
567 ):
568 nested_indices.append(i + 1)
569 serialised_attribute = self.serialise_value(element, attribute)
570 if attribute[0].id():
571 values.append(serialised_attribute)
572 else:
573 values.append(json.dumps(serialised_attribute))
574 elif isinstance(attribute, tuple):
575 attribute = self.serialise_value(element, attribute)
576 values.append(json.dumps(attribute))
577 else:
578 values.append(attribute)
579
580 if self.should_get_inverses:
581 values.append(json.dumps([e.id() for e in self.file.get_inverse(element)]))
582
583 if self.should_expand:
584 rows.extend(self.get_permutations(values, nested_indices))
585 else:
586 rows.append(values)
587
588 id_map_rows.append((element.id(), ifc_class))
589
590 if self.should_get_psets:
591 psets = ifcopenshell.util.element.get_psets(element)
592 for pset_name, pset_data in psets.items():
593 for prop_name, value in pset_data.items():
594 if prop_name == "id":
595 continue
596 if isinstance(value, list):
597 value = json.dumps(value)
598 pset_rows.append((element.id(), pset_name, prop_name, value))
599
600 if self.should_get_geometry:
601 if element.id() not in self.shape_rows and (placement := getattr(element, "ObjectPlacement", None)):
602 m = ifcopenshell.util.placement.get_local_placement(placement)
603 x, y, z = m[:, 3][0:3].tolist()

Callers 1

patchMethod · 0.95

Calls 11

serialise_valueMethod · 0.95
get_permutationsMethod · 0.95
by_typeMethod · 0.45
idMethod · 0.45
appendMethod · 0.45
is_aMethod · 0.45
get_inverseMethod · 0.45
extendMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected