Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max: updated implementation of save_scene + small QOL improvements to host #6186

Merged
merged 8 commits into from
Feb 14, 2024
Merged
5 changes: 2 additions & 3 deletions openpype/hosts/max/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def context_setting():
rt.callbacks.addScript(rt.Name('filePostOpen'),
lib.check_colorspace)

def has_unsaved_changes(self):
# TODO: how to get it from 3dsmax?
return True
def workfiles_has_unsaved_changes(self):
return rt.getSaveRequired()

def get_workfile_extensions(self):
return [".max"]
Expand Down
22 changes: 12 additions & 10 deletions openpype/hosts/max/plugins/publish/save_scene.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import pyblish.api
import os
from openpype.pipeline import registered_host


class SaveCurrentScene(pyblish.api.ContextPlugin):
"""Save current scene

"""
"""Save current scene"""

label = "Save current file"
order = pyblish.api.ExtractorOrder - 0.49
hosts = ["max"]
families = ["maxrender", "workfile"]

def process(self, context):
from pymxs import runtime as rt
folder = rt.maxFilePath
file = rt.maxFileName
current = os.path.join(folder, file)
assert context.data["currentFile"] == current
rt.saveMaxFile(current)
host = registered_host()
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
current_file = host.get_current_workfile()

assert context.data["currentFile"] == current_file

if host.workfile_has_unsaved_changes():
self.log.info(f"Saving current file: {current_file}")
host.save_workfile(current_file)
else:
self.log.debug("No unsaved changes, skipping file save..")
5 changes: 4 additions & 1 deletion openpype/hosts/max/startup/startup.ms
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

local pythonpath = systemTools.getEnvVariable "MAX_PYTHONPATH"
systemTools.setEnvVariable "PYTHONPATH" pythonpath

# opens the create menu on startup to ensure users are presented with a useful default view.
Sponge96 marked this conversation as resolved.
Show resolved Hide resolved
max create mode
moonyuet marked this conversation as resolved.
Show resolved Hide resolved

python.ExecuteFile startup
)
)