mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 19:27:10 +00:00
Add a way to load a custom IFC Schema and add util methods
This commit is contained in:
@@ -2,6 +2,13 @@ from behave import step
|
|||||||
|
|
||||||
from utils import IfcFile
|
from utils import IfcFile
|
||||||
|
|
||||||
|
@step('The IFC schema "{schema}" must be provided')
|
||||||
|
def step_impl(context, schema):
|
||||||
|
try:
|
||||||
|
IfcFile.load_schema(schema)
|
||||||
|
except:
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
||||||
@step('The IFC file "{file}" must be provided')
|
@step('The IFC file "{file}" must be provided')
|
||||||
def step_impl(context, file):
|
def step_impl(context, file):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.express
|
||||||
import ifcopenshell.util
|
import ifcopenshell.util
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
@@ -10,6 +11,13 @@ class IfcFile(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, path=None):
|
def load(cls, path=None):
|
||||||
cls.file = ifcopenshell.open(path)
|
cls.file = ifcopenshell.open(path)
|
||||||
|
if not cls.file:
|
||||||
|
assert False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load_schema(cls, path=None):
|
||||||
|
schema = ifcopenshell.express.parse(path)
|
||||||
|
ifcopenshell.register_schema(schema)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls):
|
def get(cls):
|
||||||
@@ -23,6 +31,17 @@ class IfcFile(object):
|
|||||||
return cls.get().by_guid(guid)
|
return cls.get().by_guid(guid)
|
||||||
except:
|
except:
|
||||||
assert False, "An element with the ID {} could not be found.".format(guid)
|
assert False, "An element with the ID {} could not be found.".format(guid)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def by_type(cls, ifc_type):
|
||||||
|
return cls.get().by_type(ifc_type.strip())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def by_types(cls, ifc_types):
|
||||||
|
elements = []
|
||||||
|
for ifc_type in ifc_types.split(","):
|
||||||
|
elements += cls.by_type(ifc_type.strip())
|
||||||
|
return elements
|
||||||
|
|
||||||
|
|
||||||
def assert_number(number):
|
def assert_number(number):
|
||||||
|
|||||||
Reference in New Issue
Block a user