From 9ca1e011e5e3b3321d0c9901acd4d6890d828369 Mon Sep 17 00:00:00 2001 From: atom3 Date: Fri, 30 Apr 2021 11:06:36 +0200 Subject: [PATCH] narrow try-except --- src/ifcopenshell-python/ifcopenshell/ids.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/ids.py b/src/ifcopenshell-python/ifcopenshell/ids.py index a2c407c8f9..e94fb6d614 100644 --- a/src/ifcopenshell-python/ifcopenshell/ids.py +++ b/src/ifcopenshell-python/ifcopenshell/ids.py @@ -54,12 +54,15 @@ class facet(metaclass=meta_facet): def __getattr__(self, k): try: v = self.node.getElementsByTagName(k)[0] + except IndexError: + v = None + if v: elems = [n for n in v.childNodes if n.nodeType == n.ELEMENT_NODE] if elems: return restriction(elems[0]) else: return v.firstChild.nodeValue.strip() - except IndexError: + else: return None def __iter__(self): @@ -300,8 +303,10 @@ if __name__ == "__main__": logging.basicConfig(filename=filename, level=logging.INFO, format="%(message)s") logging.FileHandler(filename, mode='w') - ids_file = ids(sys.argv[1]) - ifc_file = ifcopenshell.open(sys.argv[2]) + # ids_file = ids(sys.argv[1]) + # ifc_file = ifcopenshell.open(sys.argv[2]) + ids_file = ids(r"C:\Users\artom\Desktop\Code\IFC sandbox\IDS, MVDxml samples\IDS_test_3.xml") + ifc_file = ifcopenshell.open(r"C:\Users\artom\Desktop\Code\IFC sandbox\IFC samples\IFC Artur.ifc") ids_file.validate(ifc_file, logger)