From 8b5c13ac283324bb2510409f7113c7b3c52670ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 9 Oct 2025 11:01:25 +0200 Subject: [PATCH] Anim: do not access clipboard in Paste Global Transform poll function Remove access to the clipboard from the Paste Global Transform operator poll function, as it can cause slowdowns when there is a lot of data on the clipboard. This also means that the parsing code has to be a bit more lenient to the contents of the clipboard. And, because the error message that there is no matrix on the clipboard is now going to be shown more often, I made it a bit more friendly. Pull Request: https://projects.blender.org/blender/blender/pulls/147562 --- .../bl_operators/copy_global_transform.py | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/scripts/startup/bl_operators/copy_global_transform.py b/scripts/startup/bl_operators/copy_global_transform.py index 867695f5d9c..3260cd9ebfc 100644 --- a/scripts/startup/bl_operators/copy_global_transform.py +++ b/scripts/startup/bl_operators/copy_global_transform.py @@ -267,13 +267,28 @@ class OBJECT_OT_paste_transform(Operator): if not context.active_pose_bone and not context.active_object: cls.poll_message_set("Select an object or pose bone") return False - - clipboard = context.window_manager.clipboard.strip() - if not (clipboard.startswith("Matrix(") or clipboard.startswith(" Matrix | None: + if value.startswith("Matrix"): + return cls.parse_matrix(value) + if value.startswith(" Matrix | None: + import ast + try: + return Matrix(ast.literal_eval(value[6:])) + except Exception: + # ast.literal_eval() can raise a slew of exceptions, all of + # which means that it's not a matrix on the clipboard. + return None + @staticmethod def parse_print_m4(value: str) -> Optional[Matrix]: """Parse output from Blender's print_m4() function. @@ -285,7 +300,11 @@ class OBJECT_OT_paste_transform(Operator): if len(lines) != 4: return None - floats = tuple(tuple(float(item) for item in line.split()) for line in lines) + try: + floats = tuple(tuple(float(item) for item in line.split()) for line in lines) + except ValueError: + # Apprently not the expected format. + return None return Matrix(floats) @staticmethod @@ -296,22 +315,19 @@ class OBJECT_OT_paste_transform(Operator): if len(lines) != 4: return None - floats = tuple(tuple(float(item.strip()) for item in line.strip()[1:-1].split(',')) for line in lines) + try: + floats = tuple(tuple(float(item.strip()) for item in line.strip()[1:-1].split(',')) for line in lines) + except ValueError: + # Apprently not the expected format. + return None return Matrix(floats) def execute(self, context: Context) -> set[str]: - import ast - clipboard = context.window_manager.clipboard.strip() - if clipboard.startswith("Matrix"): - mat = Matrix(ast.literal_eval(clipboard[6:])) - elif clipboard.startswith("