From 48febb7eff207459d5fed9b3cfe04f6b432797f4 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 18 Jun 2015 13:15:33 +0000 Subject: [PATCH] Check for null values when setting attributes in IfcOpenShell-Python, also return value being set --- src/ifcopenshell-python/ifcopenshell/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/__init__.py b/src/ifcopenshell-python/ifcopenshell/__init__.py index e9f3ff8dde..d007730aa1 100644 --- a/src/ifcopenshell-python/ifcopenshell/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/__init__.py @@ -75,10 +75,14 @@ class entity_instance(object): def __getitem__(self, key): return entity_instance.wrap_value(self.wrapped_data.get_argument(key)) def __setitem__(self, idx, value): - attr_type = self.attribute_type(idx).title().replace(' ', '') - attr_type = attr_type.replace('Binary', 'String') - attr_type = attr_type.replace('Enumeration', 'String') - getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) + if value is None: + self.wrapped_data.setArgumentAsNull(idx) + else: + attr_type = self.attribute_type(idx).title().replace(' ', '') + attr_type = attr_type.replace('Binary', 'String') + attr_type = attr_type.replace('Enumeration', 'String') + getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value)) + return value def __len__(self): return len(self.wrapped_data) def __repr__(self): return repr(self.wrapped_data) def is_a(self, *args): return self.wrapped_data.is_a(*args)