Skip to content

Commit

Permalink
fix to_dict and qto
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Jul 25, 2024
1 parent 8b5dd83 commit d62675e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/compas_ifc/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ def attributes(self):
return self.to_dict()

def to_dict(self, recursive=False, ignore_fields=[], include_fields=[]):
def iter_list(values):
_values = []
for value in values:
if hasattr(value, "wrappedValue"):
value = value.wrappedValue
elif isinstance(value, Base):
value = value.to_dict(recursive=recursive)
elif isinstance(value, (list, tuple)):
value = iter_list(value)
_values.append(value)
return _values

data = {}
for key in self:
if key in ignore_fields:
Expand All @@ -148,9 +160,10 @@ def to_dict(self, recursive=False, ignore_fields=[], include_fields=[]):
if recursive and isinstance(value, Base):
value = value.to_dict(recursive=recursive)
elif recursive and isinstance(value, (list, tuple)):
value = [item.to_dict(recursive=recursive) if isinstance(item, Base) else item for item in value]
value = iter_list(value)

data[key] = value

return data

def print_attributes(self, max_depth=2):
Expand Down
5 changes: 3 additions & 2 deletions src/compas_ifc/entities/extensions/IfcObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ifcopenshell.guid
from ifcopenshell.api import run
from ifcopenshell.util.element import get_psets
from ifcopenshell.util.element import get_quantities

if TYPE_CHECKING:
from compas_ifc.entities.generated.IFC4 import IfcObject
Expand Down Expand Up @@ -52,4 +51,6 @@ def properties(self, psets):
@property
def quantities(self):
qtos = get_psets(self.entity, qtos_only=True)
return get_quantities(qtos)
for qto in qtos.values():
del qto["id"]
return qtos

0 comments on commit d62675e

Please sign in to comment.