Export auto syncs edited meshes if authoring mode enabled. See #1360.

This commit is contained in:
Dion Moult
2021-03-15 20:32:47 +11:00
parent f4f2a3d24e
commit 49ea774851
6 changed files with 18 additions and 9 deletions
@@ -20,6 +20,7 @@ class IfcExporter:
self.set_header()
if bpy.context.scene.BIMProjectProperties.is_authoring:
self.sync_object_placements()
self.sync_edited_objects()
extension = self.ifc_export_settings.output_file.split(".")[-1]
if extension == "ifczip":
with tempfile.TemporaryDirectory() as unzipped_path:
@@ -45,7 +46,8 @@ class IfcExporter:
with open(self.ifc_export_settings.output_file, "w") as outfile:
json.dump(jsonData, outfile, indent=None if self.ifc_export_settings.json_compact else 4)
if bpy.context.scene.BIMProjectProperties.is_authoring:
bpy.ops.wm.save_mainfile()
if bpy.data.filepath:
bpy.ops.wm.save_mainfile()
def set_header(self):
# TODO: add all metadata, pending bug #747
@@ -80,6 +82,16 @@ class IfcExporter:
except:
pass
def sync_edited_objects(self):
for obj_name in IfcStore.edited_objs.copy():
obj = bpy.data.objects.get(obj_name)
if not obj:
continue
representation = IfcStore.get_file().by_id(obj.data.BIMMeshProperties.ifc_definition_id)
if representation.RepresentationType == "Tessellation" or representation.RepresentationType == "Brep":
bpy.ops.bim.update_mesh_representation(obj=obj.name)
IfcStore.edited_objs.clear()
def sync_object_placement(self, obj):
blender_matrix = np.matrix(obj.matrix_world)
ifc_matrix = ifcopenshell.util.placement.get_local_placement(
@@ -12,12 +12,12 @@ def mode_callback(obj, data):
or not obj.data
or not isinstance(obj.data, bpy.types.Mesh)
or not obj.data.BIMMeshProperties.ifc_definition_id
or not bpy.context.scene.BIMGeometryProperties.should_auto_update_mesh_representations
or not bpy.context.scene.BIMProjectProperties.is_authoring
):
return
representation = IfcStore.get_file().by_id(obj.data.BIMMeshProperties.ifc_definition_id)
if representation.RepresentationType == "Tessellation" or representation.RepresentationType == "Brep":
bpy.ops.bim.update_mesh_representation(obj=obj.name)
IfcStore.edited_objs.add(obj.name)
def name_callback(obj, data):
@@ -9,6 +9,7 @@ class IfcStore:
schema = None
id_map = {}
guid_map = {}
edited_objs = set()
pset_template_path = ""
pset_template_file = None
@@ -38,12 +38,12 @@ class EditObjectPlacement(bpy.types.Operator):
self.file = IfcStore.get_file()
# TODO: determine how to deal with this module dependency
props = bpy.context.scene.BIMGeoreferenceProperties
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
for obj in objs:
if not obj.BIMObjectProperties.ifc_definition_id:
continue
matrix = np.array(obj.matrix_world)
if props.has_blender_offset and props.blender_offset_type == "OBJECT_PLACEMENT":
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
# TODO: np.array? Why not matrix?
matrix = np.array(
ifcopenshell.util.geolocation.local2global(
@@ -306,6 +306,7 @@ class UpdateMeshRepresentation(bpy.types.Operator):
for obj in objs:
self.update_obj_mesh_representation(context, obj)
IfcStore.edited_objs.discard(obj.name)
return {"FINISHED"}
def update_obj_mesh_representation(self, context, obj):
@@ -14,7 +14,6 @@ from bpy.props import (
class BIMGeometryProperties(PropertyGroup):
should_auto_update_mesh_representations: BoolProperty(name="Should Auto Update Representations", default=False)
# Revit workaround
should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False)
# RIB iTwo, DESITE BIM workaround
@@ -66,10 +66,6 @@ class BIM_PT_mesh(Panel):
layout = self.layout
props = context.active_object.data.BIMMeshProperties
sprops = context.scene.BIMGeometryProperties
row = self.layout.row()
row.prop(sprops, "should_auto_update_mesh_representations")
row = layout.row(align=True)
op = row.operator("bim.switch_representation", text="Bake Voids", icon="SELECT_SUBTRACT")
op.ifc_definition_id = props.ifc_definition_id