mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Resolve #1750. You can now save IFCs under a relative path to your Blend file.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
import uuid
|
import uuid
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -62,6 +63,8 @@ class IfcStore:
|
|||||||
def get_file():
|
def get_file():
|
||||||
if IfcStore.file is None:
|
if IfcStore.file is None:
|
||||||
IfcStore.path = bpy.context.scene.BIMProperties.ifc_file
|
IfcStore.path = bpy.context.scene.BIMProperties.ifc_file
|
||||||
|
if not os.path.isabs(IfcStore.path):
|
||||||
|
IfcStore.path = os.path.abspath(os.path.join(bpy.path.abspath("//"), IfcStore.path))
|
||||||
if IfcStore.path:
|
if IfcStore.path:
|
||||||
try:
|
try:
|
||||||
IfcStore.load_file(IfcStore.path)
|
IfcStore.load_file(IfcStore.path)
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ classes = (
|
|||||||
|
|
||||||
|
|
||||||
def menu_func_export(self, context):
|
def menu_func_export(self, context):
|
||||||
self.layout.operator(operator.ExportIFC.bl_idname, text="Industry Foundation Classes (.ifc/.ifczip/.ifcjson)")
|
op = self.layout.operator(operator.ExportIFC.bl_idname, text="Industry Foundation Classes (.ifc/.ifczip/.ifcjson)")
|
||||||
|
op.should_save_as = False
|
||||||
|
|
||||||
|
|
||||||
def menu_func_import(self, context):
|
def menu_func_import(self, context):
|
||||||
|
|||||||
@@ -741,6 +741,7 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
json_version: bpy.props.EnumProperty(items=[("4", "4", ""), ("5a", "5a", "")], name="IFC JSON Version")
|
json_version: bpy.props.EnumProperty(items=[("4", "4", ""), ("5a", "5a", "")], name="IFC JSON Version")
|
||||||
json_compact: bpy.props.BoolProperty(name="Export Compact IFCJSON", default=False)
|
json_compact: bpy.props.BoolProperty(name="Export Compact IFCJSON", default=False)
|
||||||
should_save_as: bpy.props.BoolProperty(name="Should Save As", default=False)
|
should_save_as: bpy.props.BoolProperty(name="Should Save As", default=False)
|
||||||
|
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
if not IfcStore.get_file():
|
if not IfcStore.get_file():
|
||||||
@@ -748,6 +749,8 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
if context.scene.BIMProperties.ifc_file and not self.should_save_as:
|
if context.scene.BIMProperties.ifc_file and not self.should_save_as:
|
||||||
self.filepath = context.scene.BIMProperties.ifc_file
|
self.filepath = context.scene.BIMProperties.ifc_file
|
||||||
|
if not os.path.isabs(self.filepath):
|
||||||
|
self.filepath = os.path.abspath(os.path.join(bpy.path.abspath("//"), self.filepath))
|
||||||
return self.execute(context)
|
return self.execute(context)
|
||||||
if not self.filepath:
|
if not self.filepath:
|
||||||
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".ifc")
|
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".ifc")
|
||||||
@@ -790,7 +793,9 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
if not scene.DocProperties.ifc_files:
|
if not scene.DocProperties.ifc_files:
|
||||||
new = scene.DocProperties.ifc_files.add()
|
new = scene.DocProperties.ifc_files.add()
|
||||||
new.name = output_file
|
new.name = output_file
|
||||||
if not scene.BIMProperties.ifc_file or self.should_save_as:
|
if self.use_relative_path and bpy.data.is_saved:
|
||||||
|
output_file = os.path.relpath(output_file, bpy.path.abspath("//"))
|
||||||
|
if scene.BIMProperties.ifc_file != output_file:
|
||||||
scene.BIMProperties.ifc_file = output_file
|
scene.BIMProperties.ifc_file = output_file
|
||||||
if bpy.data.is_saved and bpy.data.is_dirty and bpy.data.filepath:
|
if bpy.data.is_saved and bpy.data.is_dirty and bpy.data.filepath:
|
||||||
bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath)
|
bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath)
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ Scenario: Export IFC - with basic contents
|
|||||||
Given an empty Blender session
|
Given an empty Blender session
|
||||||
And I press "bim.load_project(filepath='{cwd}/test/files/basic.ifc')"
|
And I press "bim.load_project(filepath='{cwd}/test/files/basic.ifc')"
|
||||||
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
|
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
|
||||||
Then "scene.BIMProperties.ifc_file" is "{cwd}/test/files/basic.ifc"
|
Then "scene.BIMProperties.ifc_file" is "{cwd}/test/files/export.ifc"
|
||||||
|
|
||||||
Scenario: Export IFC - with basic contents and saving as another file
|
Scenario: Export IFC - with basic contents and saving as another file
|
||||||
Given an empty Blender session
|
Given an empty Blender session
|
||||||
@@ -332,6 +332,13 @@ Scenario: Export IFC - with basic contents and saving as another file
|
|||||||
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc', should_save_as=True)"
|
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc', should_save_as=True)"
|
||||||
Then "scene.BIMProperties.ifc_file" is "{cwd}/test/files/export.ifc"
|
Then "scene.BIMProperties.ifc_file" is "{cwd}/test/files/export.ifc"
|
||||||
|
|
||||||
|
Scenario: Export IFC - with basic contents and saving as a relative path
|
||||||
|
Given an empty Blender session
|
||||||
|
And I press "bim.load_project(filepath='{cwd}/test/files/basic.ifc')"
|
||||||
|
When I press "wm.save_mainfile(filepath='{cwd}/test/files/export.blend')"
|
||||||
|
And I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc', use_relative_path=True)"
|
||||||
|
Then "scene.BIMProperties.ifc_file" is "export.ifc"
|
||||||
|
|
||||||
Scenario: Export IFC - with deleted objects synchronised
|
Scenario: Export IFC - with deleted objects synchronised
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
When the object "IfcBuildingStorey/My Storey" is selected
|
When the object "IfcBuildingStorey/My Storey" is selected
|
||||||
|
|||||||
Reference in New Issue
Block a user