diff --git a/src/ifcblenderexport/blenderbim/bim/handler.py b/src/ifcblenderexport/blenderbim/bim/handler.py index 25527d3dd7..d9f526eaad 100644 --- a/src/ifcblenderexport/blenderbim/bim/handler.py +++ b/src/ifcblenderexport/blenderbim/bim/handler.py @@ -5,6 +5,36 @@ from bpy.app.handlers import persistent from blenderbim.bim.ifc import IfcStore +def mode_callback(obj, data): + if ( + obj.mode != "OBJECT" + 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 + ): + 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) + + +def subscribe_to(object, data_path, callback): + subscribe_to = object.path_resolve(data_path, False) + bpy.msgbus.subscribe_rna( + key=subscribe_to, + owner=object, + args=( + object, + data_path, + ), + notify=callback, + options={ + "PERSISTENT", + }, + ) + + @persistent def loadIfcStore(scene): IfcStore.file = None @@ -31,7 +61,6 @@ def loadIfcStore(scene): @persistent def ensureIfcExported(scene): - print('ensuring') if IfcStore.get_file() and not bpy.context.scene.BIMProperties.ifc_file: # The invocation pops up a file select window. # This is non-blocking, therefore the Blend file is saved before we export. diff --git a/src/ifcblenderexport/blenderbim/bim/ifc.py b/src/ifcblenderexport/blenderbim/bim/ifc.py index ac07c7b4d6..dc2fa476de 100644 --- a/src/ifcblenderexport/blenderbim/bim/ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/ifc.py @@ -1,5 +1,6 @@ import bpy import ifcopenshell +import blenderbim.bim.handler class IfcStore: @@ -36,6 +37,7 @@ class IfcStore: if hasattr(element, "GlobalId"): IfcStore.guid_map[element.GlobalId] = obj obj.BIMObjectProperties.ifc_definition_id = element.id() + blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback) @staticmethod def unlink_element(element, obj=None): diff --git a/src/ifcblenderexport/blenderbim/bim/module/geometry/prop.py b/src/ifcblenderexport/blenderbim/bim/module/geometry/prop.py index 983754d987..7efb3b0196 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/geometry/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/module/geometry/prop.py @@ -14,6 +14,7 @@ from bpy.props import ( class BIMGeometryProperties(PropertyGroup): + should_auto_update_mesh_representations: BoolProperty(name="Should Auto Update Representations", default=True) # Revit workaround should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False) # RIB iTwo, DESITE BIM workaround diff --git a/src/ifcblenderexport/blenderbim/bim/module/geometry/ui.py b/src/ifcblenderexport/blenderbim/bim/module/geometry/ui.py index 34d94e10a1..da3804fcc6 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/geometry/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/module/geometry/ui.py @@ -66,8 +66,9 @@ class BIM_PT_mesh(Panel): layout = self.layout props = context.active_object.data.BIMMeshProperties - row = layout.row() - row.operator("bim.map_representation") + 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")