From 456f45b346227dfe991c93886694891bbf606c45 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 15 Mar 2022 18:58:51 +1100 Subject: [PATCH] You can now use relative paths when browsing for file URIs. --- src/blenderbim/blenderbim/bim/__init__.py | 17 +++++++++-------- src/blenderbim/blenderbim/bim/operator.py | 9 +++++++-- src/blenderbim/test/tool/test_document.py | 2 +- .../ifcopenshell/api/document/add_reference.py | 8 +++----- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 52c4900bea..da0194dcec 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -79,17 +79,18 @@ for name in modules.keys(): classes = [ - operator.OpenUri, - operator.SelectDataDir, - operator.SelectSchemaDir, - operator.SelectIfcFile, - operator.OpenUpstream, + operator.AddIfcFile, operator.BIM_OT_add_section_plane, operator.BIM_OT_remove_section_plane, - operator.ReloadIfcFile, - operator.AddIfcFile, - operator.RemoveIfcFile, operator.ConfigureVisibility, + operator.OpenUpstream, + operator.OpenUri, + operator.ReloadIfcFile, + operator.RemoveIfcFile, + operator.SelectDataDir, + operator.SelectIfcFile, + operator.SelectSchemaDir, + operator.SelectURIAttribute, prop.StrProperty, prop.ObjProperty, prop.Attribute, diff --git a/src/blenderbim/blenderbim/bim/operator.py b/src/blenderbim/blenderbim/bim/operator.py index f4994b1405..7b171961e0 100644 --- a/src/blenderbim/blenderbim/bim/operator.py +++ b/src/blenderbim/blenderbim/bim/operator.py @@ -22,6 +22,7 @@ import json import webbrowser import ifcopenshell import blenderbim.bim.handler +import blenderbim.tool as tool from . import schema from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ui import IFCFileSelector @@ -44,8 +45,9 @@ class SelectURIAttribute(bpy.types.Operator): bl_label = "Select URI Attribute" bl_options = {"REGISTER", "UNDO"} bl_description = "Select a local file" - data_path: bpy.props.StringProperty(name="Data Path") filepath: bpy.props.StringProperty(subtype="FILE_PATH") + data_path: bpy.props.StringProperty(name="Data Path") + use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False) def execute(self, context): # data_path contains the latter half of the path to the string_value property @@ -64,7 +66,10 @@ class SelectURIAttribute(bpy.types.Operator): # Do you know a better way? pass if attribute: - attribute.string_value = self.filepath + filepath = self.filepath + if self.use_relative_path: + filepath = os.path.relpath(filepath, os.path.dirname(tool.Ifc.get_path())) + attribute.string_value = filepath return {"FINISHED"} def invoke(self, context, event): diff --git a/src/blenderbim/test/tool/test_document.py b/src/blenderbim/test/tool/test_document.py index b458eedf1e..3ef56744e0 100644 --- a/src/blenderbim/test/tool/test_document.py +++ b/src/blenderbim/test/tool/test_document.py @@ -188,7 +188,7 @@ class TestImportReferences(NewFile): assert len(props.documents) == 1 assert props.documents[0].ifc_definition_id == reference.id() assert props.documents[0].name == "Unnamed" - assert props.documents[0].identification == "X" + assert props.documents[0].identification == "*" assert props.documents[0].is_information is False diff --git a/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py b/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py index 824fb834ad..90505d9886 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py +++ b/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py @@ -25,8 +25,6 @@ class Usecase: self.settings[key] = value def execute(self): - id_attribute = "ItemReference" if self.file.schema == "IFC2X3" else "Identification" - attributes = {id_attribute: "X"} - if self.file.schema != "IFC2X3": - attributes["ReferencedDocument"] = self.settings["information"] - return self.file.create_entity("IfcDocumentReference", **attributes) + if self.file.schema == "IFC2X3": + return self.file.create_entity("IfcDocumentReference") + return self.file.create_entity("IfcDocumentReference", ReferencedDocument=self.settings["information"])