Fix #104576: FBX export of Edit Mode Objects while Blender is not in Edit Mode can fail. #104633

Merged
Member

All Objects to be exported are now checked for not being in Edit Mode
prior to exporting.

In the rare case that an Object is found to be in Edit Mode, it is
temporarily added to the current view layer, temporarily set as active
and then set to Object Mode.

If an Object cannot be set to Object mode for some reason, an error is
reported to the Operator and exporting is aborted.

All Objects to be exported are now checked for not being in Edit Mode prior to exporting. In the rare case that an Object is found to be in Edit Mode, it is temporarily added to the current view layer, temporarily set as active and then set to Object Mode. If an Object cannot be set to Object mode for some reason, an error is reported to the Operator and exporting is aborted.
Thomas Barlow force-pushed fix_inactive_edit_mode_objects_pr from db02c47f63 to e50f57e105 2023-05-26 06:05:52 +02:00 Compare
Thomas Barlow requested review from Bastien Montagne 2023-05-29 05:44:21 +02:00
Bastien Montagne requested changes 2023-06-06 17:30:48 +02:00
Bastien Montagne left a comment
Owner

Code LGTM, besides minor point noted below.

Code LGTM, besides minor point noted below.
@ -3497,0 +3500,4 @@
for obj in tuple(ctx_objects):
if not ensure_object_not_in_edit_mode(context, obj):
operator.report({'ERROR'}, "%s could not be set out of Edit Mode, so cannot be exported" % obj.name)
return ret

Should rather return {'CANCELLED'} (same below), since nothing happened.

Should rather return `{'CANCELLED'}` (same below), since nothing happened.
Author
Member

I chose returning {'FINISHED'} because if the Operator is run from Edit mode, the current mode is changed to Object mode (it would normally be changed back to the original mode at the end of the operator though this does not guarantee the same state as when starting). Similarly, ensure_object_not_in_edit_mode may have changed the mode of other Objects before finding an Object which could not be set out of Edit mode.

Even if I were to keep track of all Objects whose mode was changed, there's no guarantee that their original modes can be restored. Notably, Objects whose hide_viewport is True can exit Edit mode, but cannot enter it.

Another case is where multiple Objects are in multi-editing Edit mode at the start of the Operator. Changing to Object mode will affect all Objects in multi-editing regardless of their selection state, but changing back to Edit mode afterwards will only open selected Objects into Edit mode.

Returning {'FINISHED'} pushes an undo step so that the state from before the operator was called can be returned to easily.

If the potential changes to the modes of Objects are not considered important then I would agree with returning {'CANCELLED'}.

I chose returning `{'FINISHED'}` because if the Operator is run from Edit mode, the current mode is changed to Object mode (it would normally be changed back to the original mode at the end of the operator though this does not guarantee the same state as when starting). Similarly, `ensure_object_not_in_edit_mode` may have changed the mode of other Objects before finding an Object which could not be set out of Edit mode. Even if I were to keep track of all Objects whose mode was changed, there's no guarantee that their original modes can be restored. Notably, Objects whose `hide_viewport` is True can exit Edit mode, but cannot enter it. Another case is where multiple Objects are in multi-editing Edit mode at the start of the Operator. Changing to Object mode will affect all Objects in multi-editing regardless of their selection state, but changing back to Edit mode afterwards will only open selected Objects into Edit mode. Returning `{'FINISHED'}` pushes an undo step so that the state from before the operator was called can be returned to easily. If the potential changes to the modes of Objects are not considered important then I would agree with returning `{'CANCELLED'}`.

Yes, I think mode changes are not enough to justify a FINISHED return here.

The current situation is not fully ideal, but not very common either imho. If we wanted to be strict and bullet-proofed, I would just forbid export when any exported object is in Edit mode, but think it's more user-friendly to try to switch back to Object mode as much as we can. And accept that in some very rare, weird cases we will fail to do so and user will have to fix their scene manually before exporting.

Yes, I think mode changes are not enough to justify a `FINISHED` return here. The current situation is not fully ideal, but not very common either imho. If we wanted to be strict and bullet-proofed, I would just forbid export when any exported object is in Edit mode, but think it's more user-friendly to try to switch back to Object mode as much as we can. And accept that in some very rare, weird cases we will fail to do so and user will have to fix their scene manually before exporting.

Also, I think this should be rebased against 3.6.

Also, I think this should be rebased against 3.6.
Thomas Barlow force-pushed fix_inactive_edit_mode_objects_pr from e50f57e105 to 8fff063ff7 2023-06-08 23:45:11 +02:00 Compare
Thomas Barlow changed title from Fix #104576: FBX export of Edit Mode Objects while Blender is not in Edit Mode can fail. to Fix #104576: FBX export of Edit Mode Objects while Blender is not in Edit Mode can fail. 2023-06-08 23:45:22 +02:00
Thomas Barlow changed target branch from main to blender-v3.6-release 2023-06-08 23:45:23 +02:00
Author
Member

Rebased on 3.6 and set that as the new target branch, and changed those two returns to {'CANCELLED'}.

Rebased on 3.6 and set that as the new target branch, and changed those two returns to `{'CANCELLED'}`.
Thomas Barlow requested review from Bastien Montagne 2023-06-08 23:48:25 +02:00
Bastien Montagne approved these changes 2023-06-09 11:39:59 +02:00
Bastien Montagne merged commit c2ec9ce52d into blender-v3.6-release 2023-06-09 11:40:14 +02:00
Bastien Montagne deleted branch fix_inactive_edit_mode_objects_pr 2023-06-09 11:40:16 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104633
No description provided.