From 818c2714e8b88394018e2b528d2c00935920938c Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 18 Nov 2024 12:58:53 +0500 Subject: [PATCH] Migrate - convert IfcCountMeasures using float values to IfcNumericMeasure in ifc4x3 #5752 Traceback: Traceback (most recent call last): File "\bonsai\bim\module\patch\operator.py", line 187, in execute core.run_migrate_patch(tool.Patch, infile=self.infile, outfile=self.outfile, schema=self.schema) File "\bonsai\core\patch.py", line 30, in run_migrate_patch patch.run_migrate_patch(infile, outfile, schema) File "\bonsai\tool\patch.py", line 28, in run_migrate_patch output = ifcpatch.execute( ^^^^^^^^^^^^^^^^^ File "\ifcpatch\__init__.py", line 85, in execute patcher.patch() File "\ifcpatch\recipes\Migrate.py", line 58, in patch new_element = migrator.migrate(element, self.file_patched) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\util\schema.py", line 358, in migrate new_element = self.migrate_attributes(element, new_file, new_element, new_element_schema) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\util\schema.py", line 388, in migrate_attributes self.migrate_attribute(attribute, element, new_file, new_element, new_element_schema) File "\ifcopenshell\util\schema.py", line 489, in migrate_attribute new_value.append(self.migrate(item, new_file)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\util\schema.py", line 358, in migrate new_element = self.migrate_attributes(element, new_file, new_element, new_element_schema) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\util\schema.py", line 388, in migrate_attributes self.migrate_attribute(attribute, element, new_file, new_element, new_element_schema) File "\ifcopenshell\util\schema.py", line 484, in migrate_attribute value = self.migrate(value, new_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\util\schema.py", line 346, in migrate return new_file.create_entity(element.is_a(), element.wrappedValue) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\ifcopenshell\file.py", line 400, in create_entity e[idx] = arg ~^^^^^ File "\ifcopenshell\entity_instance.py", line 363, in __setitem__ raise TypeError( TypeError: attribute 'wrappedValue' for entity 'IFC4X3_ADD2.IfcCountMeasure' is expecting value of type 'INT', got 'float'. Error: Python: Traceback (most recent call last): File "\ifcopenshell\entity_instance.py", line 361, in __setitem__ self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value)) File "\ifcopenshell\ifcopenshell_wrapper.py", line 9271, in setArgumentAsInt return _ifcopenshell_wrapper.entity_instance_setArgumentAsInt(self, i, v) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: in method 'entity_instance_setArgumentAsInt', argument 3 of type 'int' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "\ifcopenshell\file.py", line 400, in create_entity e[idx] = arg ~^^^^^ File "\ifcopenshell\entity_instance.py", line 363, in __setitem__ raise TypeError( TypeError: attribute 'wrappedValue' for entity 'IFC4X3_ADD2.IfcCountMeasure' is expecting value of type 'INT', got 'float'. --- src/ifcopenshell-python/ifcopenshell/util/schema.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 35a042c74a..fdae211b44 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -340,7 +340,12 @@ class Migrator: self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file ) -> ifcopenshell.entity_instance: if element.id() == 0: - return new_file.create_entity(element.is_a(), element.wrappedValue) + ifc_class = element.is_a() + if ifc_class == "IfcCountMeasure" and new_file.schema == "IFC4X3": + value = element.wrappedValue + if isinstance(value, float): + ifc_class = "IfcNumericMeasure" + return new_file.create_entity(ifc_class, element.wrappedValue) try: return new_file.by_id(self.migrated_ids[element.id()]) except: