add callback for setting resolution referenced from DB record for Max

This commit is contained in:
Kayla Man 2023-03-17 22:26:36 +08:00
parent a80d6c5826
commit 72a0c01760
3 changed files with 80 additions and 1 deletions

View file

@ -6,6 +6,13 @@ from pymxs import runtime as rt
from typing import Union
import contextlib
from openpype.client import (
get_project
)
from openpype.pipeline import legacy_io
from openpype.pipeline.context_tools import get_current_project_asset
JSON_PREFIX = "JSON::"
@ -157,6 +164,63 @@ def get_multipass_setting(project_setting=None):
["multipass"])
def set_scene_resolution(width, height):
"""Set the render resolution
Args:
width(int): value of the width
height(int): value of the height
Returns:
None
"""
rt.renderWidth = width
rt.renderHeight = height
def reset_scene_resolution():
"""Apply the scene resolution from the project definition
scene resolution can be overwritten by an asset if the asset.data contains
any information regarding scene resolution .
Returns:
None
"""
project_name = legacy_io.active_project()
project_doc = get_project(project_name)
project_data = project_doc["data"]
asset_data = get_current_project_asset()["data"]
# Set project resolution
width_key = "resolutionWidth"
height_key = "resolutionHeight"
proj_width_key = project_data.get(width_key, 1920)
proj_height_key = project_data.get(height_key, 1080)
width = asset_data.get(width_key, proj_width_key)
height = asset_data.get(height_key, proj_height_key)
set_scene_resolution(width, height)
def set_context_setting():
"""Apply the project settings from the project definition
Settings can be overwritten by an asset if the asset.data contains
any information regarding those settings.
Examples of settings:
frame range
resolution
Returns:
None
"""
reset_scene_resolution()
def get_max_version():
"""
Args:

View file

@ -4,7 +4,7 @@ from qtpy import QtWidgets, QtCore
from pymxs import runtime as rt
from openpype.tools.utils import host_tools
from openpype.hosts.max.api import lib
class OpenPypeMenu(object):
"""Object representing OpenPype menu.
@ -107,6 +107,13 @@ class OpenPypeMenu(object):
workfiles_action = QtWidgets.QAction("Work Files...", openpype_menu)
workfiles_action.triggered.connect(self.workfiles_callback)
openpype_menu.addAction(workfiles_action)
openpype_menu.addSeparator()
res_action = QtWidgets.QAction("Set Resolution", openpype_menu)
res_action.triggered.connect(self.resolution_callback)
openpype_menu.addAction(res_action)
return openpype_menu
def load_callback(self):
@ -128,3 +135,7 @@ class OpenPypeMenu(object):
def workfiles_callback(self):
"""Callback to show Workfiles tool."""
host_tools.show_workfiles(parent=self.main_widget)
def resolution_callback(self):
"""Callback to reset scene resolution"""
return lib.reset_scene_resolution()

View file

@ -49,6 +49,10 @@ class MaxHost(HostBase, IWorkfileHost, ILoadHost, INewPublisher):
self.menu = OpenPypeMenu()
self._has_been_setup = True
def context_setting():
return lib.set_context_setting()
rt.callbacks.addScript(rt.Name('systemPostNew'),
context_setting)
def has_unsaved_changes(self):
# TODO: how to get it from 3dsmax?