-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: selection export and playblast creation (#601)
- Loading branch information
1 parent
74dfed7
commit 7265149
Showing
5 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
projects/framework-blender/extensions/plugins/blender_object_mode_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# :coding: utf-8 | ||
# :copyright: Copyright (c) 2024 ftrack | ||
|
||
import bpy | ||
|
||
from ftrack_utils.paths import get_temp_path | ||
|
||
from ftrack_framework_core.plugin import BasePlugin | ||
from ftrack_framework_core.exceptions.plugin import ( | ||
PluginExecutionError, | ||
PluginValidationError, | ||
) | ||
|
||
|
||
class BlenderObjectModeValidatorPlugin(BasePlugin): | ||
name = "blender_object_mode_validator" | ||
|
||
def set_mesh_objects_to_object_mode( | ||
self, store, mesh_objects_in_edit_mode | ||
): | ||
""" | ||
Set all mesh objects that are currently in edit mode to object mode. | ||
""" | ||
|
||
active_object = bpy.context.view_layer.objects.active | ||
try: | ||
for obj in mesh_objects_in_edit_mode: | ||
bpy.context.view_layer.objects.active = obj | ||
bpy.ops.object.mode_set(mode="OBJECT") | ||
except Exception as error: | ||
raise PluginExecutionError(message=error) | ||
finally: | ||
bpy.context.view_layer.objects.active = active_object | ||
|
||
def run(self, store): | ||
""" | ||
Checks if any mesh objects are currently in edit mode. | ||
We can only export a selection if all mesh objects are in object mode. | ||
""" | ||
|
||
mesh_objects_in_edit_mode = [ | ||
obj | ||
for obj in bpy.context.scene.objects | ||
if obj.type == "MESH" and obj.mode == "EDIT" | ||
] | ||
|
||
if mesh_objects_in_edit_mode: | ||
self.logger.warning( | ||
f'Some objects are still in EDIT mode. {[_.name for _ in mesh_objects_in_edit_mode]}' | ||
) | ||
raise PluginValidationError( | ||
message=f"Some objects are still in EDIT mode. Can't export scene.", | ||
on_fix_callback=lambda _: self.set_mesh_objects_to_object_mode( | ||
store, mesh_objects_in_edit_mode | ||
), | ||
) | ||
|
||
self.logger.debug("All mesh objects are properly set to object mode.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters