From 1f4c4204d0ebc45432b61ecf713af5454f53de40 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 15 Jan 2026 13:13:51 +0100 Subject: [PATCH] Re-enable setting logical with UNKNOWN in python --- .../test/test_entity_instance.py | 14 ++++++++++++++ src/ifcwrap/IfcParseWrapper.i | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/ifcopenshell-python/test/test_entity_instance.py b/src/ifcopenshell-python/test/test_entity_instance.py index f8a1b773e1..935a60c3fe 100644 --- a/src/ifcopenshell-python/test/test_entity_instance.py +++ b/src/ifcopenshell-python/test/test_entity_instance.py @@ -76,3 +76,17 @@ def test_equality(): assert f[1] == g[1] g[1].Coordinates = (1., 0.) assert f[1] != g[1] + +def test_setting_logical(): + f = ifcopenshell.file() + inst = f.createIfcPresentationLayerWithStyle(LayerOn="UNKNOWN") + assert inst.LayerOn == "UNKNOWN" + assert '.U.' in str(inst) + with pytest.raises(Exception): + inst.LayerOn = "SOME_OTHER_STRING" + inst.LayerOn = False + assert inst.LayerOn is False + assert '.F.' in str(inst) + inst.LayerOn = True + assert inst.LayerOn is True + assert '.T.' in str(inst) diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index eabdbb5be5..c4514fb8b6 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -789,6 +789,14 @@ private: boost::logic::tribool t(boost::logic::indeterminate); if (PyBool_Check(value)) { t = (value == Py_True); + } else if (PyUnicode_Check(value)) { + if (PyObject* ascii = PyUnicode_AsEncodedString(value, "UTF-8", "strict")) { + // value is kept as indeterminate + if (strcmp(PyBytes_AS_STRING(ascii), "UNKNOWN") != 0) { + throw IfcParse::IfcException("Attribute not set"); + } + Py_DECREF(ascii); + } } else { long v = to_index_long(value); if (v == 0) t = false;