diff --git a/src/ifcblenderexport/io_export_ifc/export_ifc.py b/src/ifcblenderexport/io_export_ifc/export_ifc.py index 9ab72bebbe..1d1e453303 100644 --- a/src/ifcblenderexport/io_export_ifc/export_ifc.py +++ b/src/ifcblenderexport/io_export_ifc/export_ifc.py @@ -73,6 +73,9 @@ class IfcSchema(): with open(self.schema_dir + 'ifc_types_IFC4.json') as f: self.type_map = json.load(f) + with open(self.schema_dir + 'ifc_elements_IFC4.json') as f: + self.elements = json.load(f) + def load(self): for property in self.property_file.by_type('IfcPropertySetTemplate'): if property.Name[0:4] == 'Qto_': @@ -933,7 +936,9 @@ class IfcExporter(): return properties def cast_to_base_type(self, type, value): - if self.ifc_schema.type_map[type] == 'float': + if type not in self.ifc_schema.type_map: + return value + elif self.ifc_schema.type_map[type] == 'float': return float(value) elif self.ifc_schema.type_map[type] == 'integer': return int(value) @@ -1171,11 +1176,26 @@ class IfcExporter(): 'Representation': self.get_product_shape(product) }) + for key, value in product['attributes'].items(): + type = self.get_product_attribute_type(product['class'], key) + if type is None: + continue + product['attributes'][key] = self.cast_to_base_type(type, value) + try: product['ifc'] = self.file.create_entity(product['class'], **product['attributes']) except RuntimeError as e: self.ifc_export_settings.logger.error('The product "{}/{}" could not be created: {}'.format(product['class'], product['attributes']['Name'], e.args)) + def get_product_attribute_type(self, product_class, attribute_name): + element_schema = self.ifc_schema.elements[product_class] + for a in element_schema['attributes']: + if a['name'] == attribute_name: + return a['type'] + if element_schema['parent'] in self.ifc_schema.elements: + return self.get_product_attribute_type(element_schema['parent'], attribute_name) + return None + def get_product_shape(self, product): try: shape = self.file.createIfcProductDefinitionShape(None, None, diff --git a/src/ifcblenderexport/io_export_ifc/schema/ifc_types_IFC4.json b/src/ifcblenderexport/io_export_ifc/schema/ifc_types_IFC4.json index 138c02a0c8..9f86b6df69 100644 --- a/src/ifcblenderexport/io_export_ifc/schema/ifc_types_IFC4.json +++ b/src/ifcblenderexport/io_export_ifc/schema/ifc_types_IFC4.json @@ -50,8 +50,8 @@ "IfcIdentifier": "string", "IfcIlluminanceMeasure": "float", "IfcInductanceMeasure": "float", - "IfcInteger": "float", - "IfcIntegerCountRateMeasure": "float", + "IfcInteger": "integer", + "IfcIntegerCountRateMeasure": "integer", "IfcIonConcentrationMeasure": "float", "IfcIsothermalMoistureCapacityMeasure": "float", "IfcKinematicViscosityMeasure": "float",