Fix #4617 : Switching representation in edit mode is no longer possible

This commit is contained in:
Gorgious56
2024-05-06 13:20:33 +02:00
parent b3e7975b83
commit 30b870b98d
@@ -215,6 +215,13 @@ class SwitchRepresentation(bpy.types.Operator, Operator):
disable_opening_subtractions: bpy.props.BoolProperty() disable_opening_subtractions: bpy.props.BoolProperty()
should_switch_all_meshes: bpy.props.BoolProperty() should_switch_all_meshes: bpy.props.BoolProperty()
@classmethod
def poll(cls, context):
if context.active_object.mode == "OBJECT":
return True
cls.poll_message_set("Only available in OBJECT mode - Press TAB in the viewport")
return False
def _execute(self, context): def _execute(self, context):
target_representation = tool.Ifc.get().by_id(self.ifc_definition_id) target_representation = tool.Ifc.get().by_id(self.ifc_definition_id)
target = target_representation.ContextOfItems target = target_representation.ContextOfItems
@@ -223,6 +230,8 @@ class SwitchRepresentation(bpy.types.Operator, Operator):
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if not element: if not element:
continue continue
if not obj.mode == "OBJECT":
continue
if obj == context.active_object: if obj == context.active_object:
representation = target_representation representation = target_representation
else: else:
@@ -1021,9 +1030,7 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
return return
linked_aggregate_group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), Name=self.group_name) linked_aggregate_group = ifcopenshell.api.run("group.add_group", tool.Ifc.get(), Name=self.group_name)
ifcopenshell.api.run( ifcopenshell.api.run("group.assign_group", tool.Ifc.get(), products=[element], group=linked_aggregate_group)
"group.assign_group", tool.Ifc.get(), products=[element], group=linked_aggregate_group
)
def custom_incremental_naming_for_element_assembly(old_to_new): def custom_incremental_naming_for_element_assembly(old_to_new):
for new in old_to_new.values(): for new in old_to_new.values():
@@ -1050,7 +1057,7 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
def get_max_index(parts): def get_max_index(parts):
psets = [ifcopenshell.util.element.get_pset(p, "BBIM_Linked_Aggregate") for p in parts] psets = [ifcopenshell.util.element.get_pset(p, "BBIM_Linked_Aggregate") for p in parts]
index = [i['Index'] for i in psets if i] index = [i["Index"] for i in psets if i]
if len(index) > 0: if len(index) > 0:
index = max(index) index = max(index)
return index return index
@@ -1081,7 +1088,6 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator):
] ]
tool.Ifc.run("group.assign_group", group=linked_aggregate_group[0], products=new) tool.Ifc.run("group.assign_group", group=linked_aggregate_group[0], products=new)
if len(context.selected_objects) != 1: if len(context.selected_objects) != 1:
return {"FINISHED"} return {"FINISHED"}
@@ -1261,7 +1267,6 @@ class RefreshLinkedAggregate(bpy.types.Operator):
new_obj_matrix = new_base_matrix @ matrix_diff new_obj_matrix = new_base_matrix @ matrix_diff
new_obj.matrix_world = new_obj_matrix new_obj.matrix_world = new_obj_matrix
active_element = tool.Ifc.get_entity(context.active_object) active_element = tool.Ifc.get_entity(context.active_object)
if not active_element: if not active_element:
self.report({"INFO"}, "Object has no Ifc metadata.") self.report({"INFO"}, "Object has no Ifc metadata.")