From 352d6b5ef9b9a8176a5ebc1c8b16590c3ef669f2 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 10 Apr 2023 20:31:56 +0200 Subject: [PATCH] Attempt load schema from cwd (IS THIS DANGEROUS?) --- src/ifcopenshell-python/ifcopenshell/validate.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/validate.py b/src/ifcopenshell-python/ifcopenshell/validate.py index 2121630cee..4a83f6191a 100644 --- a/src/ifcopenshell-python/ifcopenshell/validate.py +++ b/src/ifcopenshell-python/ifcopenshell/validate.py @@ -20,6 +20,7 @@ from __future__ import print_function +import os import sys import json import functools @@ -302,7 +303,19 @@ def validate(f, logger, express_rules=False): ifcopenshell.ifcopenshell_wrapper.set_log_format_json() filename = f - f = ifcopenshell.open(f) + try: + f = ifcopenshell.open(f) + except ifcopenshell.SchemaError as e: + current_dir_files = {fn.lower(): fn for fn in os.listdir('.')} + schema_name = str(e).split(' ')[-1].lower() + exists = current_dir_files.get(schema_name + '.exp') + if exists: + schema = ifcopenshell.express.parse(exists) + ifcopenshell.register_schema(schema) + + f = ifcopenshell.open(f) + else: + raise e log_internal_cpp_errors(filename, logger)