mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Save loaded paths to linked IFC models in IFC #5899
Short demo - https://imgur.com/a/3LIt9Sr
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.document
|
||||
import ifcopenshell.api.root
|
||||
import bonsai.core.tool
|
||||
import bonsai.tool as tool
|
||||
import tempfile
|
||||
@@ -238,3 +240,108 @@ class TestLoadProject(NewFile):
|
||||
assert not tool.Ifc.get()
|
||||
assert bpy.data.objects["IfcWall/Wall"]
|
||||
assert tool.Blender.is_valid_data_block(monkey)
|
||||
|
||||
|
||||
class TestLoadLinkedModels(NewFile):
|
||||
def test_load_linked_models_no_document(self):
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
subject.load_linked_models_from_ifc()
|
||||
assert len(links) == 0
|
||||
|
||||
def test_load_linked_models_document_no_references(self):
|
||||
ifc = ifcopenshell.file()
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
ifcopenshell.api.root.create_entity(ifc, "IfcProject")
|
||||
document = ifcopenshell.api.document.add_information(ifc)
|
||||
document.Name = "BBIM_Linked_Models"
|
||||
tool.Ifc.set(ifc)
|
||||
subject.load_linked_models_from_ifc()
|
||||
assert len(links) == 0
|
||||
|
||||
def test_load_linked_models_document_with_references(self):
|
||||
ifc = ifcopenshell.file()
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
ifcopenshell.api.root.create_entity(ifc, "IfcProject")
|
||||
document = ifcopenshell.api.document.add_information(ifc)
|
||||
document.Name = "BBIM_Linked_Models"
|
||||
reference = ifcopenshell.api.document.add_reference(ifc, document)
|
||||
linked_model_path = "test.ifc"
|
||||
reference.Location = linked_model_path
|
||||
tool.Ifc.set(ifc)
|
||||
subject.load_linked_models_from_ifc()
|
||||
assert len(links) == 1
|
||||
assert links[0].name == linked_model_path
|
||||
|
||||
|
||||
class TestSaveLinkedModelsToIfc(NewFile):
|
||||
def test_save_linked_models_to_ifc_no_links(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
subject.save_linked_models_to_ifc()
|
||||
assert len(ifc.by_type("IfcDocumentInformation")) == 0
|
||||
assert len(ifc.by_type("IfcDocumentReference")) == 0
|
||||
|
||||
def test_save_linked_models_to_ifc_paths_to_add(self):
|
||||
ifc = ifcopenshell.file()
|
||||
ifcopenshell.api.root.create_entity(ifc, "IfcProject")
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
link = links.add()
|
||||
linked_model_path = "test.ifc"
|
||||
link.name = linked_model_path
|
||||
tool.Ifc.set(ifc)
|
||||
subject.save_linked_models_to_ifc()
|
||||
assert len(documents := ifc.by_type("IfcDocumentInformation")) == 1
|
||||
assert documents[0].Name == "BBIM_Linked_Models"
|
||||
assert len(references := ifc.by_type("IfcDocumentReference")) == 1
|
||||
assert references[0].Location == linked_model_path
|
||||
|
||||
def test_save_linked_models_to_ifc_already_created_references(self):
|
||||
ifc = ifcopenshell.file()
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
ifcopenshell.api.root.create_entity(ifc, "IfcProject")
|
||||
|
||||
document = ifcopenshell.api.document.add_information(ifc)
|
||||
document.Name = "BBIM_Linked_Models"
|
||||
document_id = document.id()
|
||||
reference = ifcopenshell.api.document.add_reference(ifc, document)
|
||||
linked_model_path = "test.ifc"
|
||||
reference.Location = linked_model_path
|
||||
reference_id = reference.id()
|
||||
|
||||
link = links.add()
|
||||
linked_model_path = "test.ifc"
|
||||
link.name = linked_model_path
|
||||
tool.Ifc.set(ifc)
|
||||
subject.save_linked_models_to_ifc()
|
||||
|
||||
# Information and references to stay intact.
|
||||
assert len(documents := ifc.by_type("IfcDocumentInformation")) == 1
|
||||
assert documents[0].id() == document_id
|
||||
assert documents[0].Name == "BBIM_Linked_Models"
|
||||
assert len(references := ifc.by_type("IfcDocumentReference")) == 1
|
||||
assert references[0].id() == reference_id
|
||||
assert references[0].Location == linked_model_path
|
||||
|
||||
def test_save_linked_models_to_ifc_references_to_remove(self):
|
||||
ifc = ifcopenshell.file()
|
||||
links = bpy.context.scene.BIMProjectProperties.links
|
||||
ifcopenshell.api.root.create_entity(ifc, "IfcProject")
|
||||
|
||||
document = ifcopenshell.api.document.add_information(ifc)
|
||||
document.Name = "BBIM_Linked_Models"
|
||||
document_id = document.id()
|
||||
reference = ifcopenshell.api.document.add_reference(ifc, document)
|
||||
linked_model_path = "test.ifc"
|
||||
reference.Location = linked_model_path
|
||||
|
||||
tool.Ifc.set(ifc)
|
||||
subject.save_linked_models_to_ifc()
|
||||
links.clear()
|
||||
|
||||
# Remove reference for removed link.
|
||||
assert len(documents := ifc.by_type("IfcDocumentInformation")) == 1
|
||||
assert documents[0].id() == document_id
|
||||
assert documents[0].Name == "BBIM_Linked_Models"
|
||||
assert len(ifc.by_type("IfcDocumentReference")) == 0
|
||||
|
||||
Reference in New Issue
Block a user