Process derived attributes that are not redeclared (C++ has no knowledge of them)

This commit is contained in:
Thomas Krijnen
2026-01-13 08:43:52 +01:00
parent 0a9e29ce45
commit 07a01bcf54
@@ -99,9 +99,7 @@ class entity_instance_mixin:
""" """
INVALID, FORWARD, INVERSE, DERIVED = range(4) INVALID, FORWARD, INVERSE, DERIVED = range(4)
attr_cat = self.get_attribute_category(name) attr_cat = self.get_attribute_category(name)
if attr_cat == INVALID: if attr_cat == FORWARD:
raise AttributeError("entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name))
elif attr_cat == FORWARD:
idx = self.get_argument_index(name) idx = self.get_argument_index(name)
return self.get_argument(idx) return self.get_argument(idx)
elif attr_cat == INVERSE: elif attr_cat == INVERSE:
@@ -117,7 +115,7 @@ class entity_instance_mixin:
else: else:
vs = None vs = None
return vs return vs
elif attr_cat == DERIVED: else:
schema_name = self.is_a(True).split(".")[0] schema_name = self.is_a(True).split(".")[0]
try: try:
rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}") rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}")
@@ -146,10 +144,11 @@ class entity_instance_mixin:
decl = decl.supertype() decl = decl.supertype()
for sty in yield_supertypes(): for sty in yield_supertypes():
fn = getattr(rules, f"calc_{sty}_{name}", None) if fn := getattr(rules, f"calc_{sty}_{name}", None):
if fn:
return fn(self) return fn(self)
raise AttributeError("entity instance of type '%s' has no attribute '%s'" % (self.is_a(True), name))
@staticmethod @staticmethod
def walk(f: Callable[[Any], bool], g: Callable[[Any], Any], value: Any) -> Any: def walk(f: Callable[[Any], bool], g: Callable[[Any], Any], value: Any) -> Any:
"""Applies a transformation to `value` based on a given condition. """Applies a transformation to `value` based on a given condition.