mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 10:52:45 +00:00
Export auto syncs edited meshes if authoring mode enabled. See #1360.
This commit is contained in:
@@ -20,6 +20,7 @@ class IfcExporter:
|
|||||||
self.set_header()
|
self.set_header()
|
||||||
if bpy.context.scene.BIMProjectProperties.is_authoring:
|
if bpy.context.scene.BIMProjectProperties.is_authoring:
|
||||||
self.sync_object_placements()
|
self.sync_object_placements()
|
||||||
|
self.sync_edited_objects()
|
||||||
extension = self.ifc_export_settings.output_file.split(".")[-1]
|
extension = self.ifc_export_settings.output_file.split(".")[-1]
|
||||||
if extension == "ifczip":
|
if extension == "ifczip":
|
||||||
with tempfile.TemporaryDirectory() as unzipped_path:
|
with tempfile.TemporaryDirectory() as unzipped_path:
|
||||||
@@ -45,7 +46,8 @@ class IfcExporter:
|
|||||||
with open(self.ifc_export_settings.output_file, "w") as outfile:
|
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)
|
json.dump(jsonData, outfile, indent=None if self.ifc_export_settings.json_compact else 4)
|
||||||
if bpy.context.scene.BIMProjectProperties.is_authoring:
|
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):
|
def set_header(self):
|
||||||
# TODO: add all metadata, pending bug #747
|
# TODO: add all metadata, pending bug #747
|
||||||
@@ -80,6 +82,16 @@ class IfcExporter:
|
|||||||
except:
|
except:
|
||||||
pass
|
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):
|
def sync_object_placement(self, obj):
|
||||||
blender_matrix = np.matrix(obj.matrix_world)
|
blender_matrix = np.matrix(obj.matrix_world)
|
||||||
ifc_matrix = ifcopenshell.util.placement.get_local_placement(
|
ifc_matrix = ifcopenshell.util.placement.get_local_placement(
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ def mode_callback(obj, data):
|
|||||||
or not obj.data
|
or not obj.data
|
||||||
or not isinstance(obj.data, bpy.types.Mesh)
|
or not isinstance(obj.data, bpy.types.Mesh)
|
||||||
or not obj.data.BIMMeshProperties.ifc_definition_id
|
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
|
return
|
||||||
representation = IfcStore.get_file().by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
representation = IfcStore.get_file().by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||||
if representation.RepresentationType == "Tessellation" or representation.RepresentationType == "Brep":
|
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):
|
def name_callback(obj, data):
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class IfcStore:
|
|||||||
schema = None
|
schema = None
|
||||||
id_map = {}
|
id_map = {}
|
||||||
guid_map = {}
|
guid_map = {}
|
||||||
|
edited_objs = set()
|
||||||
pset_template_path = ""
|
pset_template_path = ""
|
||||||
pset_template_file = None
|
pset_template_file = None
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ class EditObjectPlacement(bpy.types.Operator):
|
|||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
# TODO: determine how to deal with this module dependency
|
# TODO: determine how to deal with this module dependency
|
||||||
props = bpy.context.scene.BIMGeoreferenceProperties
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||||
continue
|
continue
|
||||||
matrix = np.array(obj.matrix_world)
|
matrix = np.array(obj.matrix_world)
|
||||||
if props.has_blender_offset and props.blender_offset_type == "OBJECT_PLACEMENT":
|
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?
|
# TODO: np.array? Why not matrix?
|
||||||
matrix = np.array(
|
matrix = np.array(
|
||||||
ifcopenshell.util.geolocation.local2global(
|
ifcopenshell.util.geolocation.local2global(
|
||||||
@@ -306,6 +306,7 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
|||||||
|
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
self.update_obj_mesh_representation(context, obj)
|
self.update_obj_mesh_representation(context, obj)
|
||||||
|
IfcStore.edited_objs.discard(obj.name)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def update_obj_mesh_representation(self, context, obj):
|
def update_obj_mesh_representation(self, context, obj):
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from bpy.props import (
|
|||||||
|
|
||||||
|
|
||||||
class BIMGeometryProperties(PropertyGroup):
|
class BIMGeometryProperties(PropertyGroup):
|
||||||
should_auto_update_mesh_representations: BoolProperty(name="Should Auto Update Representations", default=False)
|
|
||||||
# Revit workaround
|
# Revit workaround
|
||||||
should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False)
|
should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False)
|
||||||
# RIB iTwo, DESITE BIM workaround
|
# RIB iTwo, DESITE BIM workaround
|
||||||
|
|||||||
@@ -66,10 +66,6 @@ class BIM_PT_mesh(Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
props = context.active_object.data.BIMMeshProperties
|
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)
|
row = layout.row(align=True)
|
||||||
op = row.operator("bim.switch_representation", text="Bake Voids", icon="SELECT_SUBTRACT")
|
op = row.operator("bim.switch_representation", text="Bake Voids", icon="SELECT_SUBTRACT")
|
||||||
op.ifc_definition_id = props.ifc_definition_id
|
op.ifc_definition_id = props.ifc_definition_id
|
||||||
|
|||||||
Reference in New Issue
Block a user