More options to save .ifc as relative path in blender

This commit is contained in:
Andrej730
2023-06-21 17:30:34 +05:00
parent 7f10eaa14f
commit 89146ea046
3 changed files with 33 additions and 10 deletions
@@ -74,19 +74,21 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
append_all: bpy.props.BoolProperty(default=False)
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
def execute(self, context):
IfcStore.begin_transaction(self)
old_filepath = IfcStore.library_path
result = self._execute(context)
self.transaction_data = {"old_filepath": old_filepath, "filepath": self.filepath}
self.transaction_data = {"old_filepath": old_filepath, "filepath": self.get_filepath()}
IfcStore.add_transaction_operation(self)
IfcStore.end_transaction(self)
return result
def _execute(self, context):
IfcStore.library_path = self.filepath
IfcStore.library_file = ifcopenshell.open(self.filepath)
filepath = self.get_filepath()
IfcStore.library_path = filepath
IfcStore.library_file = ifcopenshell.open(filepath)
bpy.ops.bim.refresh_library()
if context.area:
context.area.tag_redraw()
@@ -525,11 +527,12 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
is_advanced: bpy.props.BoolProperty(name="Enable Advanced Mode", default=False)
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
def execute(self, context):
if not self.is_existing_ifc_file():
return {"FINISHED"}
context.scene.BIMProperties.ifc_file = self.filepath
context.scene.BIMProperties.ifc_file = self.get_filepath()
context.scene.BIMProjectProperties.is_loading = True
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
if not self.is_advanced:
+9 -5
View File
@@ -94,10 +94,11 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
bl_description = "Select a different IFC file"
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
def execute(self, context):
if self.is_existing_ifc_file():
context.scene.BIMProperties.ifc_file = self.filepath
context.scene.BIMProperties.ifc_file = self.get_filepath()
return {"FINISHED"}
def invoke(self, context, event):
@@ -105,7 +106,7 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
return {"RUNNING_MODAL"}
class ReloadSelectedIfcFile(bpy.types.Operator, IFCFileSelector):
class ReloadSelectedIfcFile(bpy.types.Operator):
bl_idname = "bim.reload_selected_ifc_file"
bl_label = "Reload selected IFC File"
bl_options = {"REGISTER", "UNDO"}
@@ -113,9 +114,12 @@ class ReloadSelectedIfcFile(bpy.types.Operator, IFCFileSelector):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
self.filepath = context.scene.BIMProperties.ifc_file
if self.is_existing_ifc_file():
context.scene.BIMProperties.ifc_file = context.scene.BIMProperties.ifc_file
filepath = context.scene.BIMProperties.ifc_file
valid_file = os.path.exists(filepath) and "ifc" in os.path.splitext(filepath)[1].lower()
if not valid_file:
self.report({"ERROR"}, f"Couldn't find .ifc file by the path '{filepath}'")
return {"ERROR"}
context.scene.BIMProperties.ifc_file = context.scene.BIMProperties.ifc_file
return {"FINISHED"}
+17 -1
View File
@@ -39,14 +39,23 @@ class IFCFileSelector:
filepath = self.filepath
return os.path.exists(filepath) and "ifc" in os.path.splitext(filepath)[1].lower()
def get_filepath(self):
"""get filepath taking into account relative paths"""
if self.use_relative_path:
filepath = os.path.relpath(self.filepath, bpy.path.abspath("//"))
else:
filepath = self.filepath
return filepath
def draw(self, context):
# Access filepath & Directory https://blender.stackexchange.com/a/207665
params = context.space_data.params
# Decode byte string https://stackoverflow.com/a/47737082/
directory = Path(params.directory.decode("utf-8"))
filepath = os.path.join(directory, params.filename)
layout = self.layout
if self.is_existing_ifc_file(filepath):
box = self.layout.box()
box = layout.box()
box.label(text="IFC Header Specifications", icon="INFO")
header_data = IfcHeaderExtractor(filepath).extract()
for key, value in header_data.items():
@@ -65,6 +74,13 @@ class IFCFileSelector:
op.outfile = filepath[0:-4] + "-IFC4.ifc"
op.schema = "IFC4"
if bpy.data.is_saved:
layout.prop(self, "use_relative_path")
else:
self.use_relative_path = False
layout.label(text="Save the .blend file first ")
layout.label(text="to use relative paths for .ifc.")
class BIM_PT_section_plane(Panel):
bl_label = "Temporary Section Cutaways"