From 15bc96817970cde88108ab046d1c1ed189b5c6e2 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 23 Jan 2025 22:59:41 +1100 Subject: [PATCH] Remove dead code from schema.py Slowly getting to a point where we can completely delete this legacy file. --- src/bonsai/bonsai/bim/schema.py | 44 ++----------------------------- src/bonsai/bonsai/tool/blender.py | 5 +++- 2 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/bonsai/bonsai/bim/schema.py b/src/bonsai/bonsai/bim/schema.py index 93300e0c45..b3f68e6c63 100644 --- a/src/bonsai/bonsai/bim/schema.py +++ b/src/bonsai/bonsai/bim/schema.py @@ -16,14 +16,9 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . -import os -import bpy -import json import ifcopenshell import ifcopenshell.util.pset -from pathlib import Path - -cwd = os.path.dirname(os.path.realpath(__file__)) +import bonsai.tool as tool class IfcSchema: @@ -31,10 +26,6 @@ class IfcSchema: if schema_identifier not in ("IFC2X3", "IFC4", "IFC4X3_ADD2"): schema_identifier = "IFC4" self.schema_identifier = schema_identifier - - self.schema_dir = Path(cwd).joinpath("schema") - self.data_dir = Path(cwd).joinpath("data") - # TODO: Make it less troublesome self.products = [ "IfcElement", "IfcSpatialElement", @@ -47,13 +38,10 @@ class IfcSchema: "IfcElementType", "IfcAnnotation", ] - self.elements = {} - self.classification_files = {} - self.classifications = {} self.load_pset_templates() def load_pset_templates(self): - property_paths = self.data_dir.joinpath("pset").glob("*.ifc") + property_paths = tool.Blender.get_data_dir_path("pset").glob("*.ifc") self.psetqto = ifcopenshell.util.pset.get_template(self.schema_identifier) # Keep only the first template, which is the official buildingSMART one self.psetqto.templates = self.psetqto.templates[0:1] @@ -63,34 +51,6 @@ class IfcSchema: for path in property_paths: self.psetqto.templates.append(ifcopenshell.open(path)) - def load_classification(self, name, classification_index=None): - if name not in self.classifications: - if classification_index is not None: - self.classification_files[name] = ifcopenshell.file.from_string( - bpy.context.scene.BIMProperties.classifications[classification_index].data - ) - else: - classification_path = os.path.join(self.schema_dir, "classifications", "{}.ifc".format(name)) - self.classification_files[name] = ifcopenshell.open(classification_path) - self.classifications[name] = self.classification_files[name].by_type("IfcClassification")[0] - classification = self.classifications[name] - bpy.context.scene.BIMProperties.active_classification_name = self.classifications[name].Name - return {"name": "", "description": "", "children": self.get_classification_references(classification)} - - def get_classification_references(self, classification): - references = {} - if not hasattr(classification, "HasReferences") or not classification.HasReferences: - return references - for reference in classification.HasReferences: - references[reference.Identification] = { - "location": reference.Location, - "identification": reference.Identification, - "name": reference.Name, - "description": reference.Description, - "children": self.get_classification_references(reference), - } - return references - ifc = IfcSchema() diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index bd2d5c01e7..2ab3a34e97 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -1454,7 +1454,10 @@ class Blender(bonsai.core.tool.Blender): @classmethod def get_user_data_dir(cls) -> Path: - return Path(bpy.context.scene.BIMProperties.data_dir) + try: + return Path(bpy.context.scene.BIMProperties.data_dir) + except AttributeError: + return Path() @classmethod def get_data_dir_path(cls, relative_path: Union[str, Path]) -> Path: