mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Make util.element.get_psets() support IfcComplexProperty
This commit is contained in:
@@ -4,32 +4,50 @@ def get_psets(element):
|
|||||||
if element.is_a('IfcTypeObject'):
|
if element.is_a('IfcTypeObject'):
|
||||||
if element.HasPropertySets:
|
if element.HasPropertySets:
|
||||||
for definition in element.HasPropertySets:
|
for definition in element.HasPropertySets:
|
||||||
psets[definition.Name] = get_properties(definition)
|
psets[definition.Name] = get_property_definition(definition)
|
||||||
else:
|
else:
|
||||||
for relationship in element.IsDefinedBy:
|
for relationship in element.IsDefinedBy:
|
||||||
if relationship.is_a('IfcRelDefinesByProperties'):
|
if relationship.is_a('IfcRelDefinesByProperties'):
|
||||||
definition = relationship.RelatingPropertyDefinition
|
definition = relationship.RelatingPropertyDefinition
|
||||||
psets[definition.Name] = get_properties(definition)
|
psets[definition.Name] = get_property_definition(definition)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
print('failed to load properties: {}'.format(e))
|
print('failed to load properties: {}'.format(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return psets
|
return psets
|
||||||
|
|
||||||
def get_properties(definition):
|
|
||||||
|
def get_property_definition(definition):
|
||||||
if definition is not None:
|
if definition is not None:
|
||||||
props = {}
|
props = {}
|
||||||
if definition.is_a('IfcElementQuantity'):
|
if definition.is_a('IfcElementQuantity'):
|
||||||
for q in definition.Quantities:
|
props.update(get_quantities(definition.Quantities))
|
||||||
if q.is_a('IfcPhysicalSimpleQuantity'):
|
|
||||||
props[q.Name] = q[3]
|
|
||||||
elif definition.is_a('IfcPropertySet'):
|
elif definition.is_a('IfcPropertySet'):
|
||||||
for prop in definition.HasProperties:
|
props.update(get_properties(definition.HasProperties))
|
||||||
if prop.is_a('IfcPropertySingleValue'):
|
|
||||||
props[prop.Name] = prop.NominalValue
|
|
||||||
else:
|
else:
|
||||||
# Entity introduced in IFC4
|
# Entity introduced in IFC4
|
||||||
# definition.is_a('IfcPreDefinedPropertySet'):
|
# definition.is_a('IfcPreDefinedPropertySet'):
|
||||||
for prop in range(4, len(definition)):
|
for prop in range(4, len(definition)):
|
||||||
props[definition.attribute_name(prop)] = definition[prop]
|
props[definition.attribute_name(prop)] = definition[prop]
|
||||||
return props
|
return props
|
||||||
|
|
||||||
|
|
||||||
|
def get_quantities(quantities):
|
||||||
|
results = {}
|
||||||
|
for quantity in quantities:
|
||||||
|
if quantity.is_a('IfcPhysicalSimpleQuantity'):
|
||||||
|
results[quantity.Name] = quantity[3]
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def get_properties(properties):
|
||||||
|
results = {}
|
||||||
|
for prop in properties:
|
||||||
|
if prop.is_a('IfcPropertySingleValue'):
|
||||||
|
results[prop.Name] = prop.NominalValue
|
||||||
|
elif prop.is_a('IfcComplexProperty'):
|
||||||
|
data = prop.get_info()
|
||||||
|
data['properties'] = get_properties(prop.HasProperties)
|
||||||
|
del(data['HasProperties'])
|
||||||
|
results[prop.Name] = data
|
||||||
|
return results
|
||||||
|
|||||||
Reference in New Issue
Block a user