Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/util/element.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.6 KiB
Python
Raw Normal View History

def get_psets(element):
psets = {}
try:
2020-11-01 20:08:27 +07:00
if element.is_a("IfcTypeObject"):
if element.HasPropertySets:
for definition in element.HasPropertySets:
psets[definition.Name] = get_property_definition(definition)
else:
for relationship in element.IsDefinedBy:
2020-11-01 20:08:27 +07:00
if relationship.is_a("IfcRelDefinesByProperties"):
definition = relationship.RelatingPropertyDefinition
psets[definition.Name] = get_property_definition(definition)
except Exception as e:
import traceback
2020-11-01 20:08:27 +07:00
print("failed to load properties: {}".format(e))
traceback.print_exc()
return psets
def get_property_definition(definition):
if definition is not None:
props = {}
2020-11-01 20:08:27 +07:00
if definition.is_a("IfcElementQuantity"):
props.update(get_quantities(definition.Quantities))
2020-11-01 20:08:27 +07:00
elif definition.is_a("IfcPropertySet"):
props.update(get_properties(definition.HasProperties))
else:
# Entity introduced in IFC4
# definition.is_a('IfcPreDefinedPropertySet'):
for prop in range(4, len(definition)):
props[definition.attribute_name(prop)] = definition[prop]
return props
def get_quantities(quantities):
results = {}
for quantity in quantities:
2020-11-01 20:08:27 +07:00
if quantity.is_a("IfcPhysicalSimpleQuantity"):
results[quantity.Name] = quantity[3]
return results
def get_properties(properties):
results = {}
for prop in properties:
2020-11-01 20:08:27 +07:00
if prop.is_a("IfcPropertySingleValue"):
2020-09-05 12:20:16 +10:00
results[prop.Name] = prop.NominalValue.wrappedValue
2020-11-01 20:08:27 +07:00
elif prop.is_a("IfcComplexProperty"):
data = prop.get_info()
2020-11-01 20:08:27 +07:00
data["properties"] = get_properties(prop.HasProperties)
del data["HasProperties"]
results[prop.Name] = data
return results
2020-08-08 17:58:45 +10:00
def get_type(element):
2020-11-01 20:08:27 +07:00
if hasattr(element, "IsTypedBy") and element.IsTypedBy:
2020-08-08 17:58:45 +10:00
return element.IsTypedBy[0].RelatingType
2020-11-01 20:08:27 +07:00
elif hasattr(element, "IsDefinedBy") and element.IsDefinedBy: # IFC2X3
2020-08-08 17:58:45 +10:00
for relationship in element.IsDefinedBy:
2020-11-01 20:08:27 +07:00
if relationship.is_a("IfcRelDefinesByType"):
2020-08-08 17:58:45 +10:00
return relationship.RelatingType
def replace_attribute(element, old, new):
for i, attribute in enumerate(element):
if attribute == old:
element[i] = new
elif isinstance(attribute, tuple):
new_attribute = list(attribute)
for j, item in enumerate(attribute):
if item == old:
new_attribute[j] = new
element[i] = new_attribute