mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
create path configuration by checking subdirectory & set up the default tmeplate for path configuration purpose if the project creation is not enabled
This commit is contained in:
parent
2bc9ce8770
commit
5650a70548
4 changed files with 74 additions and 15 deletions
|
|
@ -3,21 +3,24 @@
|
|||
import os
|
||||
import logging
|
||||
from operator import attrgetter
|
||||
|
||||
import errno
|
||||
import json
|
||||
|
||||
from ayon_core.host import HostBase, IWorkfileHost, ILoadHost, IPublishHost
|
||||
import pyblish.api
|
||||
from ayon_core.pipeline import (
|
||||
get_current_project_name,
|
||||
register_creator_plugin_path,
|
||||
register_loader_plugin_path,
|
||||
AVALON_CONTAINER_ID,
|
||||
AYON_CONTAINER_ID,
|
||||
)
|
||||
from ayon_core.lib import register_event_callback
|
||||
from ayon_max.api.menu import AYONMenu
|
||||
from ayon_max.api import lib
|
||||
from ayon_max.api.plugin import MS_CUSTOM_ATTRIB
|
||||
from ayon_max import MAX_HOST_DIR
|
||||
from ayon_max.lib import create_workspace_mxp
|
||||
|
||||
from pymxs import runtime as rt # noqa
|
||||
|
||||
|
|
@ -47,18 +50,25 @@ class MaxHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
|
|||
register_loader_plugin_path(LOAD_PATH)
|
||||
register_creator_plugin_path(CREATE_PATH)
|
||||
|
||||
# self._register_callbacks()
|
||||
_set_project()
|
||||
|
||||
self.menu = AYONMenu()
|
||||
|
||||
register_event_callback("workfile.open.before", on_before_open)
|
||||
self._has_been_setup = True
|
||||
|
||||
rt.callbacks.addScript(rt.Name('systemPostNew'), on_new)
|
||||
def context_setting():
|
||||
return lib.set_context_setting()
|
||||
|
||||
rt.callbacks.addScript(rt.Name('systemPostNew'),
|
||||
context_setting)
|
||||
|
||||
rt.callbacks.addScript(rt.Name('filePostOpen'),
|
||||
lib.check_colorspace)
|
||||
|
||||
rt.callbacks.addScript(rt.Name('postWorkspaceChange'),
|
||||
self._deferred_menu_creation)
|
||||
|
||||
rt.NodeEventCallback(
|
||||
nameChanged=lib.update_modifier_node_names)
|
||||
|
||||
|
|
@ -159,14 +169,6 @@ def ls() -> list:
|
|||
yield lib.read(container)
|
||||
|
||||
|
||||
def on_new():
|
||||
lib.set_context_setting()
|
||||
if rt.checkForSave():
|
||||
rt.resetMaxFile(rt.Name("noPrompt"))
|
||||
rt.clearUndoBuffer()
|
||||
rt.redrawViews()
|
||||
|
||||
|
||||
def containerise(name: str, nodes: list, context,
|
||||
namespace=None, loader=None, suffix="_CON"):
|
||||
data = {
|
||||
|
|
@ -185,6 +187,27 @@ def containerise(name: str, nodes: list, context,
|
|||
return container
|
||||
|
||||
|
||||
def _set_project():
|
||||
workdir = os.getenv("AYON_WORKDIR")
|
||||
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
mxp_filepath = os.path.join(workdir, "workspace.mxp")
|
||||
if os.path.exists(mxp_filepath):
|
||||
rt.pathConfig.load(mxp_filepath)
|
||||
directory_count = rt.pathConfig.getProjectSubDirectoryCount()
|
||||
for count in range(directory_count):
|
||||
proj_dir = rt.pathConfig.getProjectSubDirectory(count)
|
||||
os.makedirs(proj_dir, exist_ok=True)
|
||||
rt.pathConfig.doProjectSetupStepsUsingDirectory(workdir)
|
||||
rt.pathConfig.setCurrentProjectFolder(workdir)
|
||||
|
||||
|
||||
def on_before_open():
|
||||
"""Check and set up project before opening workfile
|
||||
"""
|
||||
_set_project()
|
||||
|
||||
|
||||
def load_custom_attribute_data():
|
||||
"""Re-loading the AYON custom parameter built by the creator
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from ayon_applications import PreLaunchHook, LaunchTypes
|
||||
from ayon_core.hosts.max.mxp import create_workspace_mxp
|
||||
from ayon_max.mxp import create_workspace_mxp
|
||||
|
||||
|
||||
class PreCopyMxp(PreLaunchHook):
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ def create_workspace_mxp(workdir, project_name):
|
|||
log.debug("No mxp workspace setting found in the "
|
||||
"latest Max Addon. Please update to 0.1.8")
|
||||
return
|
||||
|
||||
max_script = default_mxp_template()
|
||||
if mxp_workspace.get("enabled_project_creation"):
|
||||
max_script = mxp_workspace.get("mxp_workspace_script")
|
||||
# Skip if mxp script in settings is empty
|
||||
|
|
@ -27,7 +29,40 @@ def create_workspace_mxp(workdir, project_name):
|
|||
log.debug("File 'workspace.mxp' not created. Settings value is empty.")
|
||||
return
|
||||
|
||||
with open(dst_filepath, "w") as mxp_file:
|
||||
mxp_file.write(max_script)
|
||||
with open(dst_filepath, "w") as mxp_file:
|
||||
mxp_file.write(max_script)
|
||||
|
||||
return dst_filepath
|
||||
return dst_filepath
|
||||
|
||||
|
||||
def default_mxp_template():
|
||||
"""Return text script for the path configuration if
|
||||
users do not enable project creation in AYON project
|
||||
setting
|
||||
"""
|
||||
mxp_template = "\n".join((
|
||||
'[Directories]',
|
||||
'Animations= ./',
|
||||
'Archives=./',
|
||||
'AutoBackup=./',
|
||||
'BitmapProxies=./',
|
||||
'Fluid Simulations=./',
|
||||
'Images=./',
|
||||
'MaxStart=./',
|
||||
'Previews=./',
|
||||
'RenderAssets=./',
|
||||
'RenderOutput= ./renders/3dsmax',
|
||||
'Scenes=./',
|
||||
'Sounds=./',
|
||||
'[XReferenceDirs]',
|
||||
'Dir1=./',
|
||||
'[BitmapDirs]',
|
||||
'Dir1=C:/Program Files/Autodesk/3ds Max 2023/Maps',
|
||||
'Dir2=C:/Program Files/Autodesk/3ds Max 2023/Maps/glare',
|
||||
'Dir3=C:/Program Files/Autodesk/3ds Max 2023/Maps/adskMtl',
|
||||
'Dir4=C:/Program Files/Autodesk/3ds Max 2023/Maps/Noise',
|
||||
'Dir5=C:/Program Files/Autodesk/3ds Max 2023/Maps/mental_mill',
|
||||
'Dir6=C:/Program Files/Autodesk/3ds Max 2023/Maps/fx',
|
||||
'Dir7=C:/Program Files/Autodesk/3ds Max 2023/Maps/Particle Flow Presets',
|
||||
))
|
||||
return mxp_template
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ DEFAULT_MXP_WORKSPACE_SETTINGS = "\n".join((
|
|||
'MaxStart=./',
|
||||
'Previews=./previews',
|
||||
'RenderAssets=./sceneassets/renderassets',
|
||||
'RenderOutput= ./renders/3dsmax'
|
||||
'Scenes=./',
|
||||
'Sounds=./sceneassets/sounds',
|
||||
'[XReferenceDirs]',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue