From 0b7efa19fe44845b3d1ec6628d6f8ff23903b2cb Mon Sep 17 00:00:00 2001 From: ChunYou Date: Wed, 13 Mar 2024 13:05:38 +0000 Subject: [PATCH 1/5] Maximise viewport instead of changing layout. Adding validator for extended viewport --- .../hosts/max/api/preview_animation.py | 25 +++++++++++-------- .../publish/validate_extended_viewport.py | 21 ++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py diff --git a/client/ayon_core/hosts/max/api/preview_animation.py b/client/ayon_core/hosts/max/api/preview_animation.py index f715efa53d..3872c4e493 100644 --- a/client/ayon_core/hosts/max/api/preview_animation.py +++ b/client/ayon_core/hosts/max/api/preview_animation.py @@ -31,23 +31,26 @@ def viewport_layout_and_camera(camera, layout="layout_1"): layout (str): layout to use in viewport, defaults to `layout_1` Use None to not change viewport layout during context. """ + needs_maximise = 0 + # Set to first active non extended viewport + rt.viewport.activeViewportEx(1) original_camera = rt.viewport.getCamera() - original_layout = rt.viewport.getLayout() - if not original_camera: - # if there is no original camera - # use the current camera as original - original_camera = rt.getNodeByName(camera) + original_type = rt.viewport.getType() review_camera = rt.getNodeByName(camera) + try: - if layout is not None: - layout = rt.Name(layout) - if rt.viewport.getLayout() != layout: - rt.viewport.setLayout(layout) + if rt.viewport.getLayout()!=rt.name(layout): + rt.execute("max tool maximize") + needs_maximise = 1 rt.viewport.setCamera(review_camera) yield finally: - rt.viewport.setLayout(original_layout) - rt.viewport.setCamera(original_camera) + if needs_maximise == 1: + rt.execute("max tool maximize") + if original_type == rt.Name("view_camera"): + rt.viewport.setCamera(original_camera) + else: + rt.viewport.setType(original_type) @contextlib.contextmanager diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py new file mode 100644 index 0000000000..96686970c6 --- /dev/null +++ b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +import pyblish.api +from ayon_core.pipeline import PublishValidationError +from pymxs import runtime as rt + + +class ValidateExtendedViewport(pyblish.api.InstancePlugin): + """Validate if the first viewport is an extended viewport.""" + + order = pyblish.api.ValidatorOrder + families = ["review"] + hosts = ["max"] + label = "Validate Extended Viewport" + + def process(self, instance): + try: + rt.viewport.activeViewportEx(1) + except RuntimeError: + raise PublishValidationError( + "Please make sure one viewport is not an extended viewport", title=self.label) + From fc85f469f7884852f7d1036c61c14a375c80a1aa Mon Sep 17 00:00:00 2001 From: ChunYou Date: Thu, 14 Mar 2024 02:17:05 +0000 Subject: [PATCH 2/5] Update Publish Validation Error Description --- .../hosts/max/plugins/publish/validate_extended_viewport.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py index 96686970c6..7d9e3dc6fe 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py @@ -17,5 +17,8 @@ class ValidateExtendedViewport(pyblish.api.InstancePlugin): rt.viewport.activeViewportEx(1) except RuntimeError: raise PublishValidationError( - "Please make sure one viewport is not an extended viewport", title=self.label) + "Please make sure at least one viewport is not an extended viewport but a 3dsmax supported viewport " + "i.e camera/persp/orthographic view. To rectify it, please go to view in the top menubar, " + "go to Views -> Viewports Configuration -> layout and right click on one of the panels to change " + "it.", title=self.label) From e8bfb903620d07f8a74b76db075384a48c5a106d Mon Sep 17 00:00:00 2001 From: ChunYou Date: Thu, 14 Mar 2024 11:54:54 +0000 Subject: [PATCH 3/5] Change Instance to Context --- .../hosts/max/plugins/publish/validate_extended_viewport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py index 7d9e3dc6fe..8c64508a8b 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py @@ -4,7 +4,7 @@ from ayon_core.pipeline import PublishValidationError from pymxs import runtime as rt -class ValidateExtendedViewport(pyblish.api.InstancePlugin): +class ValidateExtendedViewport(pyblish.api.ContextPlugin): """Validate if the first viewport is an extended viewport.""" order = pyblish.api.ValidatorOrder @@ -12,7 +12,7 @@ class ValidateExtendedViewport(pyblish.api.InstancePlugin): hosts = ["max"] label = "Validate Extended Viewport" - def process(self, instance): + def process(self, context): try: rt.viewport.activeViewportEx(1) except RuntimeError: From df83dfaf40fc5f87767e2645f96d05efbe7f97e8 Mon Sep 17 00:00:00 2001 From: r42-chun <73248638+r42-chun@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:08:37 +0000 Subject: [PATCH 4/5] Commit description and rectify line length Co-authored-by: Roy Nieterau --- .../plugins/publish/validate_extended_viewport.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py index 8c64508a8b..ed476ec874 100644 --- a/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py +++ b/client/ayon_core/hosts/max/plugins/publish/validate_extended_viewport.py @@ -17,8 +17,13 @@ class ValidateExtendedViewport(pyblish.api.ContextPlugin): rt.viewport.activeViewportEx(1) except RuntimeError: raise PublishValidationError( - "Please make sure at least one viewport is not an extended viewport but a 3dsmax supported viewport " - "i.e camera/persp/orthographic view. To rectify it, please go to view in the top menubar, " - "go to Views -> Viewports Configuration -> layout and right click on one of the panels to change " - "it.", title=self.label) + "Please make sure one viewport is not an extended viewport", + description = ( + "Please make sure at least one viewport is not an " + "extended viewport but a 3dsmax supported viewport " + "i.e camera/persp/orthographic view.\n\n" + "To rectify it, please go to view in the top menubar, " + "go to Views -> Viewports Configuration -> Layout and " + "right click on one of the panels to change it." + )) From 305c76b6016185fd770a00d587907bd88847e7c5 Mon Sep 17 00:00:00 2001 From: r42-chun <73248638+r42-chun@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:08:57 +0000 Subject: [PATCH 5/5] Add space for cosmetics Co-authored-by: Roy Nieterau --- client/ayon_core/hosts/max/api/preview_animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/hosts/max/api/preview_animation.py b/client/ayon_core/hosts/max/api/preview_animation.py index 3872c4e493..399d3b6222 100644 --- a/client/ayon_core/hosts/max/api/preview_animation.py +++ b/client/ayon_core/hosts/max/api/preview_animation.py @@ -39,7 +39,7 @@ def viewport_layout_and_camera(camera, layout="layout_1"): review_camera = rt.getNodeByName(camera) try: - if rt.viewport.getLayout()!=rt.name(layout): + if rt.viewport.getLayout() != rt.name(layout): rt.execute("max tool maximize") needs_maximise = 1 rt.viewport.setCamera(review_camera)