Check and correct for object mode in operator, not in poll, as operator may be called headlessly (e.g. in export function).

Note that after the operator has been refactored to use the core / tool design pattern, the poll code may return if necessary.
This commit is contained in:
Dion Moult
2022-08-02 19:31:32 +10:00
parent 1f11354188
commit 759e134e3b
@@ -130,10 +130,6 @@ class UpdateRepresentation(bpy.types.Operator):
obj: bpy.props.StringProperty()
ifc_representation_class: bpy.props.StringProperty()
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.mode == "OBJECT"
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
@@ -141,6 +137,10 @@ class UpdateRepresentation(bpy.types.Operator):
if not ContextData.is_loaded:
ContextData.load(IfcStore.get_file())
if context.active_object and context.active_object.mode != "OBJECT":
# Ensure mode is object to prevent invalid mesh data causing CTD
bpy.ops.object.mode_set(mode="OBJECT", toggle=False)
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
self.file = IfcStore.get_file()