Skip to content

Commit

Permalink
Return of the missing button for regenerating global id
Browse files Browse the repository at this point in the history
Was about to implement to find that we already have "bim.generate_global_id" and it just was lost at some point. Returned it to the attributes UI. It also allows Updating guids for all selected elements on Shift+Click.

This also can be useful to solve MergeProject and other guids conflicts, see example issue in https://community.osarch.org/discussion/2062/bbim-mergeproject-patch-not-separating-elements-in-different-buildings

Example - https://imgur.com/a/mvRtyER
  • Loading branch information
Andrej730 committed Apr 2, 2024
1 parent 38afce1 commit 96302a5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/blenderbim/blenderbim/bim/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -321,7 +325,6 @@ def draw_filter(layout, filter_groups, data, module):
op.module = module



# TODO this should move into ifcopenshell.util


Expand Down
44 changes: 35 additions & 9 deletions src/blenderbim/blenderbim/bim/module/attribute/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,46 @@ def callback(attributes, prop):
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"}


Expand Down
3 changes: 3 additions & 0 deletions src/blenderbim/blenderbim/bim/module/debug/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def draw(self, context):
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
Expand Down

0 comments on commit 96302a5

Please sign in to comment.