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

Method _execute

src/bonsai/bonsai/bim/operator.py:1019–1084  ·  view source on GitHub ↗
(self, context)

Source from the content-addressed store, hash-verified

1017 filename_ext = ".ifc"
1018
1019 def _execute(self, context):
1020 import ifcdiff
1021
1022 old = tool.Ifc.get()
1023 new: ifcopenshell.file
1024 new = ifcopenshell.open(self.filepath)
1025
1026 ifc_diff = ifcdiff.IfcDiff(old, new, relationships=[])
1027 ifc_diff.diff()
1028
1029 changed_elements = set([k for k, v in ifc_diff.change_register.items() if "geometry_changed" in v])
1030
1031 for global_id in ifc_diff.deleted_elements | changed_elements:
1032 element = tool.Ifc.get().by_guid(global_id)
1033 obj = tool.Ifc.get_object(element)
1034 if obj:
1035 bpy.data.objects.remove(obj)
1036
1037 # STEP IDs may change, but we assume the GlobalID to be constant
1038 obj_map = {}
1039 for obj in bpy.data.objects:
1040 if obj.library:
1041 continue
1042 element = tool.Ifc.get_entity(obj)
1043 if element and hasattr(element, "GlobalId"):
1044 obj_map[obj.name] = element.GlobalId
1045
1046 delta_elements = [new.by_guid(global_id) for global_id in ifc_diff.added_elements | changed_elements]
1047 tool.Ifc.set(new)
1048
1049 for obj in bpy.data.objects:
1050 if obj.library:
1051 continue
1052 global_id = obj_map.get(obj.name)
1053 if global_id:
1054 try:
1055 tool.Ifc.link(new.by_guid(global_id), obj)
1056 except:
1057 # Still prototyping, so things like types definitely won't work
1058 print("Could not relink", obj)
1059
1060 start = time.time()
1061 logger = logging.getLogger("ImportIFC")
1062 path_log = tool.Blender.get_data_dir_path("process.log")
1063 if not os.access(path_log.parent, os.W_OK):
1064 path_log = os.path.join(
1065 tempfile.mkdtemp(dir=tool.Blender.get_addon_preferences().tmp_dir or None), "process.log"
1066 )
1067 logging.basicConfig(
1068 filename=path_log,
1069 filemode="a",
1070 level=logging.DEBUG,
1071 )
1072 settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger)
1073 settings.has_filter = True
1074 settings.should_filter_spatial_elements = False
1075 settings.elements = delta_elements
1076 settings.logger.info("Starting import")

Callers

nothing calls this directly

Calls 15

diffMethod · 0.95
executeMethod · 0.95
printFunction · 0.85
openMethod · 0.80
get_data_dir_pathMethod · 0.80
get_addon_preferencesMethod · 0.80
formatMethod · 0.80
get_bim_propsMethod · 0.80
setFunction · 0.50
getMethod · 0.45
itemsMethod · 0.45
by_guidMethod · 0.45

Tested by

no test coverage detected