property set extraction (#2)
This commit is contained in:
@@ -4,6 +4,8 @@ from ifcopenshell.entity_instance import entity_instance
|
|||||||
from specklepy.objects.base import Base
|
from specklepy.objects.base import Base
|
||||||
from specklepy.objects.data_objects import DataObject
|
from specklepy.objects.data_objects import DataObject
|
||||||
|
|
||||||
|
from speckleifc.property_extraction import extract_properties
|
||||||
|
|
||||||
|
|
||||||
def data_object_to_speckle(
|
def data_object_to_speckle(
|
||||||
display_value: list[Base],
|
display_value: list[Base],
|
||||||
@@ -15,7 +17,7 @@ def data_object_to_speckle(
|
|||||||
|
|
||||||
data_object = DataObject(
|
data_object = DataObject(
|
||||||
applicationId=guid,
|
applicationId=guid,
|
||||||
properties={},
|
properties=extract_properties(step_element),
|
||||||
name=name or guid,
|
name=name or guid,
|
||||||
displayValue=display_value,
|
displayValue=display_value,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from specklepy.objects.base import Base
|
|||||||
from specklepy.objects.data_objects import DataObject
|
from specklepy.objects.data_objects import DataObject
|
||||||
from specklepy.objects.models.collections.collection import Collection
|
from specklepy.objects.models.collections.collection import Collection
|
||||||
|
|
||||||
|
from speckleifc.property_extraction import extract_properties
|
||||||
|
|
||||||
|
|
||||||
def spatial_element_to_speckle(
|
def spatial_element_to_speckle(
|
||||||
display_value: list[Base],
|
display_value: list[Base],
|
||||||
@@ -31,7 +33,7 @@ def _convert_as_data_object(
|
|||||||
name = cast(str, step_element.Name or step_element.LongName or guid)
|
name = cast(str, step_element.Name or step_element.LongName or guid)
|
||||||
data_object = DataObject(
|
data_object = DataObject(
|
||||||
applicationId=guid,
|
applicationId=guid,
|
||||||
properties={},
|
properties=extract_properties(step_element),
|
||||||
name=name,
|
name=name,
|
||||||
displayValue=display_value,
|
displayValue=display_value,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from ifcopenshell.entity_instance import entity_instance
|
||||||
|
|
||||||
|
|
||||||
|
def extract_properties(element: entity_instance) -> dict[str, object]:
|
||||||
|
result: dict[str, object] = {}
|
||||||
|
|
||||||
|
for rel in getattr(element, "IsDefinedBy", []):
|
||||||
|
if not rel.is_a("IfcRelDefinesByProperties"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
prop_set = rel.RelatingPropertyDefinition
|
||||||
|
if not prop_set.is_a("IfcPropertySet"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
set_name = prop_set.Name
|
||||||
|
properties: dict[str, Any] = {}
|
||||||
|
|
||||||
|
for prop in prop_set.HasProperties:
|
||||||
|
name = prop.Name
|
||||||
|
|
||||||
|
if prop.is_a("IfcPropertySingleValue"):
|
||||||
|
val = prop.NominalValue
|
||||||
|
if val is not None:
|
||||||
|
properties[name] = (
|
||||||
|
val.wrappedValue if hasattr(val, "wrappedValue") else val
|
||||||
|
)
|
||||||
|
elif prop.is_a("IfcPropertyListValue"):
|
||||||
|
values = getattr(prop, "ListValues", None)
|
||||||
|
if values:
|
||||||
|
properties[name] = [
|
||||||
|
v.wrappedValue if hasattr(v, "wrappedValue") else v
|
||||||
|
for v in values
|
||||||
|
]
|
||||||
|
elif prop.is_a("IfcPropertyEnumeratedValue"):
|
||||||
|
values = getattr(prop, "EnumerationValues", None)
|
||||||
|
if values:
|
||||||
|
properties[name] = [
|
||||||
|
v.wrappedValue if hasattr(v, "wrappedValue") else v
|
||||||
|
for v in values
|
||||||
|
]
|
||||||
|
|
||||||
|
# elif prop.is_a("IfcPropertyTableValue"):
|
||||||
|
# properties[name] = #not sure if we want to support these...
|
||||||
|
|
||||||
|
if properties:
|
||||||
|
result[set_name] = properties
|
||||||
|
|
||||||
|
return result
|
||||||
Reference in New Issue
Block a user