diff --git a/src/blenderbim/blenderbim/bim/helper.py b/src/blenderbim/blenderbim/bim/helper.py index 7694316c9a..e42b94013a 100644 --- a/src/blenderbim/blenderbim/bim/helper.py +++ b/src/blenderbim/blenderbim/bim/helper.py @@ -75,6 +75,10 @@ def draw_attribute(attribute, layout, copy_operator=None): op.data_path = attribute.path_from_id("string_value") if attribute.is_optional: layout.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="") + + if attribute.name == "GlobalId": + layout.operator("bim.generate_global_id", icon="FILE_REFRESH", text="") + if copy_operator: op = layout.operator(f"{copy_operator}", text="", icon="COPYDOWN") op.name = attribute.name @@ -321,7 +325,6 @@ def draw_filter(layout, filter_groups, data, module): op.module = module - # TODO this should move into ifcopenshell.util diff --git a/src/blenderbim/blenderbim/bim/module/attribute/operator.py b/src/blenderbim/blenderbim/bim/module/attribute/operator.py index 89b2d06df2..89b32597be 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/operator.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/operator.py @@ -120,20 +120,46 @@ class EditAttributes(bpy.types.Operator, Operator): return {"FINISHED"} -class GenerateGlobalId(bpy.types.Operator): +class GenerateGlobalId(bpy.types.Operator, Operator): bl_idname = "bim.generate_global_id" bl_label = "Regenerate GlobalId" + bl_description = "Regenerate GlobalId\n\nSHIFT+CLICK to regenerate GlobalIds for all selected objects" bl_options = {"REGISTER", "UNDO"} - def execute(self, context): - index = context.active_object.BIMAttributeProperties.attributes.find("GlobalId") - if index >= 0: - global_id = context.active_object.BIMAttributeProperties.attributes[index] + use_selected: bpy.props.BoolProperty(name="Use All Selected Objects", default=False, options={"SKIP_SAVE"}) + + def invoke(self, context, event): + # using all selected objects on shift+click + # make sure to use SKIP_SAVE on property, otherwise it might get stuck + if event.type == "LEFTMOUSE" and event.shift: + self.use_selected = True + return self.execute(context) + + def _execute(self, context): + if self.use_selected: + for obj in context.selected_objects: + element = tool.Ifc.get_entity(obj) + if not element or not element.is_a("IfcRoot"): + continue + element.GlobalId = ifcopenshell.guid.new() + + obj = context.active_object + if not obj or not obj.BIMAttributeProperties.is_editing_attributes: + return {"FINISHED"} + + props = obj.BIMAttributeProperties + element = tool.Ifc.get_entity(obj) + + if not element.is_a("IfcRoot"): + return {"FINISHED"} + + if self.use_selected and obj in context.selected_objects: + # guid value was already regenerated, just update the ui prop + guid_value = element.GlobalId else: - global_id = context.active_object.BIMAttributeProperties.attributes.add() - global_id.name = "GlobalId" - global_id.data_type = "string" - global_id.string_value = ifcopenshell.guid.new() + guid_value = ifcopenshell.guid.new() + + props.attributes["GlobalId"].string_value = guid_value return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/debug/ui.py b/src/blenderbim/blenderbim/bim/module/debug/ui.py index 21a6e11f80..6b90987e62 100644 --- a/src/blenderbim/blenderbim/bim/module/debug/ui.py +++ b/src/blenderbim/blenderbim/bim/module/debug/ui.py @@ -75,6 +75,9 @@ class BIM_PT_debug(Panel): row = layout.row() row.operator("bim.profile_import_ifc") + row = layout.row() + row.operator("bim.generate_global_id") + row = layout.split(factor=0.5, align=True) row.operator("bim.create_shape_from_step_id").should_include_curves = False row.operator("bim.create_shape_from_step_id", text="", icon="IPO_ELASTIC").should_include_curves = True