mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Slightly more robust deletion tracking.
This commit is contained in:
@@ -42,7 +42,8 @@ class IfcExporter:
|
||||
self.file = IfcStore.get_file()
|
||||
self.set_header()
|
||||
if bpy.context.scene.BIMProjectProperties.is_authoring:
|
||||
self.sync_object_placements_and_deletions()
|
||||
self.sync_deletions()
|
||||
self.sync_object_placements()
|
||||
self.sync_edited_objects()
|
||||
extension = self.ifc_export_settings.output_file.split(".")[-1]
|
||||
if extension == "ifczip":
|
||||
@@ -83,10 +84,13 @@ class IfcExporter:
|
||||
self.get_application_name(), self.get_application_version()
|
||||
)
|
||||
|
||||
def sync_object_placements_and_deletions(self):
|
||||
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
||||
to_delete = []
|
||||
def sync_deletions(self):
|
||||
for ifc_definition_id in IfcStore.deleted_ids:
|
||||
product = self.file.by_id(ifc_definition_id)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, **{"product": product})
|
||||
|
||||
def sync_object_placements(self):
|
||||
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
||||
for ifc_definition_id, obj in IfcStore.id_map.items():
|
||||
try:
|
||||
if isinstance(obj, bpy.types.Material):
|
||||
@@ -95,13 +99,6 @@ class IfcExporter:
|
||||
self.sync_object_placement(obj)
|
||||
except ReferenceError:
|
||||
pass # The object is likely deleted
|
||||
if self.should_delete(obj):
|
||||
to_delete.append(ifc_definition_id)
|
||||
|
||||
for ifc_definition_id in to_delete:
|
||||
product = self.file.by_id(ifc_definition_id)
|
||||
IfcStore.unlink_element(product)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, **{"product": product})
|
||||
|
||||
def sync_edited_objects(self):
|
||||
for obj in IfcStore.edited_objs.copy():
|
||||
@@ -149,15 +146,6 @@ class IfcExporter:
|
||||
if grid_obj.matrix_world != obj.matrix_world:
|
||||
bpy.ops.bim.update_representation(obj=obj.name)
|
||||
|
||||
def should_delete(self, obj):
|
||||
try:
|
||||
# This will throw an exception if the Blender object no longer exists
|
||||
foo = obj.name
|
||||
foo
|
||||
return False
|
||||
except:
|
||||
return True
|
||||
|
||||
def get_application_name(self):
|
||||
return "BlenderBIM"
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class IfcStore:
|
||||
schema = None
|
||||
id_map = {}
|
||||
guid_map = {}
|
||||
deleted_ids = set()
|
||||
edited_objs = set()
|
||||
pset_template_path = ""
|
||||
pset_template_file = None
|
||||
@@ -50,6 +51,7 @@ class IfcStore:
|
||||
IfcStore.schema = None
|
||||
IfcStore.id_map = {}
|
||||
IfcStore.guid_map = {}
|
||||
IfcStore.deleted_ids = set()
|
||||
IfcStore.edited_objs = set()
|
||||
IfcStore.pset_template_path = ""
|
||||
IfcStore.pset_template_file = None
|
||||
|
||||
@@ -326,6 +326,15 @@ Scenario: Export IFC - with basic contents
|
||||
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Export IFC - with deleted objects synchronised
|
||||
Given an empty IFC project
|
||||
When the object "IfcBuildingStorey/My Storey" is selected
|
||||
And I press "object.delete"
|
||||
And I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
|
||||
And an empty Blender session is started
|
||||
And I press "bim.load_project(filepath='{cwd}/test/files/export.ifc')"
|
||||
Then the object "IfcBuildingStorey/My Storey" does not exist
|
||||
|
||||
Scenario: Export IFC - with moved object location synchronised
|
||||
Given an empty IFC project
|
||||
When the object "IfcBuildingStorey/My Storey" is moved to "0,0,1"
|
||||
|
||||
Reference in New Issue
Block a user