mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 06:32:09 +00:00
More options to save .ifc as relative path in blender
This commit is contained in:
@@ -74,19 +74,21 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||||
append_all: bpy.props.BoolProperty(default=False)
|
append_all: bpy.props.BoolProperty(default=False)
|
||||||
|
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
IfcStore.begin_transaction(self)
|
IfcStore.begin_transaction(self)
|
||||||
old_filepath = IfcStore.library_path
|
old_filepath = IfcStore.library_path
|
||||||
result = self._execute(context)
|
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.add_transaction_operation(self)
|
||||||
IfcStore.end_transaction(self)
|
IfcStore.end_transaction(self)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
IfcStore.library_path = self.filepath
|
filepath = self.get_filepath()
|
||||||
IfcStore.library_file = ifcopenshell.open(self.filepath)
|
IfcStore.library_path = filepath
|
||||||
|
IfcStore.library_file = ifcopenshell.open(filepath)
|
||||||
bpy.ops.bim.refresh_library()
|
bpy.ops.bim.refresh_library()
|
||||||
if context.area:
|
if context.area:
|
||||||
context.area.tag_redraw()
|
context.area.tag_redraw()
|
||||||
@@ -525,11 +527,12 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
|
|||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||||
is_advanced: bpy.props.BoolProperty(name="Enable Advanced Mode", default=False)
|
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):
|
def execute(self, context):
|
||||||
if not self.is_existing_ifc_file():
|
if not self.is_existing_ifc_file():
|
||||||
return {"FINISHED"}
|
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.is_loading = True
|
||||||
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
|
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
|
||||||
if not self.is_advanced:
|
if not self.is_advanced:
|
||||||
|
|||||||
@@ -94,10 +94,11 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
bl_description = "Select a different IFC file"
|
bl_description = "Select a different IFC file"
|
||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
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):
|
def execute(self, context):
|
||||||
if self.is_existing_ifc_file():
|
if self.is_existing_ifc_file():
|
||||||
context.scene.BIMProperties.ifc_file = self.filepath
|
context.scene.BIMProperties.ifc_file = self.get_filepath()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
@@ -105,7 +106,7 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
return {"RUNNING_MODAL"}
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
|
||||||
class ReloadSelectedIfcFile(bpy.types.Operator, IFCFileSelector):
|
class ReloadSelectedIfcFile(bpy.types.Operator):
|
||||||
bl_idname = "bim.reload_selected_ifc_file"
|
bl_idname = "bim.reload_selected_ifc_file"
|
||||||
bl_label = "Reload selected IFC File"
|
bl_label = "Reload selected IFC File"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -113,9 +114,12 @@ class ReloadSelectedIfcFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.filepath = context.scene.BIMProperties.ifc_file
|
filepath = context.scene.BIMProperties.ifc_file
|
||||||
if self.is_existing_ifc_file():
|
valid_file = os.path.exists(filepath) and "ifc" in os.path.splitext(filepath)[1].lower()
|
||||||
context.scene.BIMProperties.ifc_file = context.scene.BIMProperties.ifc_file
|
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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,14 +39,23 @@ class IFCFileSelector:
|
|||||||
filepath = self.filepath
|
filepath = self.filepath
|
||||||
return os.path.exists(filepath) and "ifc" in os.path.splitext(filepath)[1].lower()
|
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):
|
def draw(self, context):
|
||||||
# Access filepath & Directory https://blender.stackexchange.com/a/207665
|
# Access filepath & Directory https://blender.stackexchange.com/a/207665
|
||||||
params = context.space_data.params
|
params = context.space_data.params
|
||||||
# Decode byte string https://stackoverflow.com/a/47737082/
|
# Decode byte string https://stackoverflow.com/a/47737082/
|
||||||
directory = Path(params.directory.decode("utf-8"))
|
directory = Path(params.directory.decode("utf-8"))
|
||||||
filepath = os.path.join(directory, params.filename)
|
filepath = os.path.join(directory, params.filename)
|
||||||
|
layout = self.layout
|
||||||
if self.is_existing_ifc_file(filepath):
|
if self.is_existing_ifc_file(filepath):
|
||||||
box = self.layout.box()
|
box = layout.box()
|
||||||
box.label(text="IFC Header Specifications", icon="INFO")
|
box.label(text="IFC Header Specifications", icon="INFO")
|
||||||
header_data = IfcHeaderExtractor(filepath).extract()
|
header_data = IfcHeaderExtractor(filepath).extract()
|
||||||
for key, value in header_data.items():
|
for key, value in header_data.items():
|
||||||
@@ -65,6 +74,13 @@ class IFCFileSelector:
|
|||||||
op.outfile = filepath[0:-4] + "-IFC4.ifc"
|
op.outfile = filepath[0:-4] + "-IFC4.ifc"
|
||||||
op.schema = "IFC4"
|
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):
|
class BIM_PT_section_plane(Panel):
|
||||||
bl_label = "Temporary Section Cutaways"
|
bl_label = "Temporary Section Cutaways"
|
||||||
|
|||||||
Reference in New Issue
Block a user