Skip to content

Commit 81399ff

Browse files
committed
Support loading project without clearing Blender session
It wasn't working anymore after 27a2c94. Importing IFC file as just geometry should be a separate option from 'should_start_fresh_session' and I've added it as 'import_without_ifc_data' property during project load (now both options are also available for users in project load dialog - https://i.imgur.com/Fvbv4Dy.png)
1 parent 21cfd03 commit 81399ff

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

src/bonsai/bonsai/bim/module/project/operator.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,25 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
645645
bl_description = "Load an existing IFC project"
646646
filepath: bpy.props.StringProperty(subtype="FILE_PATH", options={"SKIP_SAVE"})
647647
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml;*.ifcsqlite", options={"HIDDEN"})
648-
is_advanced: bpy.props.BoolProperty(name="Enable Advanced Mode", default=False)
648+
is_advanced: bpy.props.BoolProperty(
649+
name="Enable Advanced Mode",
650+
description="Load IFC file with advanced settings. Checking this option will skip loading IFC file and will open advanced load settings",
651+
default=False,
652+
)
649653
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
650-
should_start_fresh_session: bpy.props.BoolProperty(name="Should Start Fresh Session", default=True)
654+
should_start_fresh_session: bpy.props.BoolProperty(
655+
name="Should Start Fresh Session",
656+
description="Clear current Blender session before loading IFC",
657+
default=True,
658+
)
659+
import_without_ifc_data: bpy.props.BoolProperty(
660+
name="Import Without IFC Data",
661+
description=(
662+
"Import IFC objects as Blender objects without any IFC metadata and authoring capabilities."
663+
"Can be useful for work with purely IFC geometry"
664+
),
665+
default=False,
666+
)
651667
use_detailed_tooltip: bpy.props.BoolProperty(default=False, options={"HIDDEN"})
652668

653669
@classmethod
@@ -721,6 +737,10 @@ def finish_loading_project(self, context):
721737
for obj in bpy.data.objects:
722738
bpy.data.objects.remove(obj)
723739

740+
# To be safe from any accidental IFC data in the previous session.
741+
if not self.is_advanced and not self.should_start_fresh_session:
742+
bpy.ops.bim.convert_to_blender()
743+
724744
filepath = Path(self.get_filepath())
725745
context.scene.BIMProperties.ifc_file = filepath.as_posix()
726746
context.scene.BIMProjectProperties.is_loading = True
@@ -730,7 +750,7 @@ def finish_loading_project(self, context):
730750

731751
if not self.is_advanced:
732752
bpy.ops.bim.load_project_elements()
733-
if not self.should_start_fresh_session:
753+
if self.import_without_ifc_data:
734754
bpy.ops.bim.convert_to_blender()
735755
except:
736756
bonsai.last_error = traceback.format_exc()
@@ -745,6 +765,8 @@ def invoke(self, context, event):
745765

746766
def draw(self, context):
747767
self.layout.prop(self, "is_advanced")
768+
self.layout.prop(self, "should_start_fresh_session")
769+
self.layout.prop(self, "import_without_ifc_data")
748770
IFCFileSelector.draw(self, context)
749771

750772

src/bonsai/bonsai/bim/module/project/ui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
def file_import_menu(self, context):
2929
op = self.layout.operator("bim.load_project", text="IFC (Geometry Only) (.ifc/.ifczip/.ifcxml)")
30+
op.import_without_ifc_data = True
3031
op.should_start_fresh_session = False
3132

3233

src/bonsai/test/tool/test_project.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,45 @@ def test_add_recent_ifc_project(self):
196196
subject.add_recent_ifc_project(ifc_file)
197197
assert filepath.stat().st_size != 0
198198
assert subject.get_recent_ifc_projects() == [ifc_file]
199+
200+
201+
class TestLoadProject(NewFile):
202+
def test_load_project_and_start_fresh_sesion(self):
203+
filepath = Path("test/files/basic.ifc")
204+
bpy.ops.mesh.primitive_monkey_add()
205+
monkey = bpy.context.object
206+
assert monkey
207+
bpy.ops.bim.load_project(filepath=filepath.as_posix())
208+
assert tool.Ifc.get()
209+
assert not tool.Blender.is_valid_data_block(monkey)
210+
211+
def test_load_project_without_starting_fresh_sesion(self):
212+
filepath = Path("test/files/basic.ifc")
213+
bpy.ops.mesh.primitive_monkey_add()
214+
monkey = bpy.context.object
215+
assert monkey
216+
bpy.ops.bim.load_project(filepath=filepath.as_posix(), should_start_fresh_session=False)
217+
assert tool.Ifc.get()
218+
assert tool.Blender.is_valid_data_block(monkey)
219+
220+
def test_load_project_without_ifc_data(self):
221+
filepath = Path("test/files/basic.ifc")
222+
bpy.ops.mesh.primitive_monkey_add()
223+
monkey = bpy.context.object
224+
assert monkey
225+
bpy.ops.bim.load_project(filepath=filepath.as_posix(), import_without_ifc_data=True)
226+
assert not tool.Ifc.get()
227+
assert bpy.data.objects["IfcWall/Wall"]
228+
assert not tool.Blender.is_valid_data_block(monkey)
229+
230+
def test_load_project_without_ifc_data_and_restarting_session(self):
231+
filepath = Path("test/files/basic.ifc")
232+
bpy.ops.mesh.primitive_monkey_add()
233+
monkey = bpy.context.object
234+
assert monkey
235+
bpy.ops.bim.load_project(
236+
filepath=filepath.as_posix(), import_without_ifc_data=True, should_start_fresh_session=False
237+
)
238+
assert not tool.Ifc.get()
239+
assert bpy.data.objects["IfcWall/Wall"]
240+
assert tool.Blender.is_valid_data_block(monkey)

0 commit comments

Comments
 (0)