mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 08:02:29 +00:00
Fix export bug with uncast attribute data types
This commit is contained in:
@@ -73,6 +73,9 @@ class IfcSchema():
|
|||||||
with open(self.schema_dir + 'ifc_types_IFC4.json') as f:
|
with open(self.schema_dir + 'ifc_types_IFC4.json') as f:
|
||||||
self.type_map = json.load(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):
|
def load(self):
|
||||||
for property in self.property_file.by_type('IfcPropertySetTemplate'):
|
for property in self.property_file.by_type('IfcPropertySetTemplate'):
|
||||||
if property.Name[0:4] == 'Qto_':
|
if property.Name[0:4] == 'Qto_':
|
||||||
@@ -933,7 +936,9 @@ class IfcExporter():
|
|||||||
return properties
|
return properties
|
||||||
|
|
||||||
def cast_to_base_type(self, type, value):
|
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)
|
return float(value)
|
||||||
elif self.ifc_schema.type_map[type] == 'integer':
|
elif self.ifc_schema.type_map[type] == 'integer':
|
||||||
return int(value)
|
return int(value)
|
||||||
@@ -1171,11 +1176,26 @@ class IfcExporter():
|
|||||||
'Representation': self.get_product_shape(product)
|
'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:
|
try:
|
||||||
product['ifc'] = self.file.create_entity(product['class'], **product['attributes'])
|
product['ifc'] = self.file.create_entity(product['class'], **product['attributes'])
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
self.ifc_export_settings.logger.error('The product "{}/{}" could not be created: {}'.format(product['class'], product['attributes']['Name'], e.args))
|
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):
|
def get_product_shape(self, product):
|
||||||
try:
|
try:
|
||||||
shape = self.file.createIfcProductDefinitionShape(None, None,
|
shape = self.file.createIfcProductDefinitionShape(None, None,
|
||||||
|
|||||||
@@ -50,8 +50,8 @@
|
|||||||
"IfcIdentifier": "string",
|
"IfcIdentifier": "string",
|
||||||
"IfcIlluminanceMeasure": "float",
|
"IfcIlluminanceMeasure": "float",
|
||||||
"IfcInductanceMeasure": "float",
|
"IfcInductanceMeasure": "float",
|
||||||
"IfcInteger": "float",
|
"IfcInteger": "integer",
|
||||||
"IfcIntegerCountRateMeasure": "float",
|
"IfcIntegerCountRateMeasure": "integer",
|
||||||
"IfcIonConcentrationMeasure": "float",
|
"IfcIonConcentrationMeasure": "float",
|
||||||
"IfcIsothermalMoistureCapacityMeasure": "float",
|
"IfcIsothermalMoistureCapacityMeasure": "float",
|
||||||
"IfcKinematicViscosityMeasure": "float",
|
"IfcKinematicViscosityMeasure": "float",
|
||||||
|
|||||||
Reference in New Issue
Block a user