From 50aaa96ecb40ab437c1a0eefc42c8d3ede98cdbf Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 28 Sep 2017 16:29:36 +0200 Subject: [PATCH] Fix `mtoa` errors on launch by loading deferred, cleanup id generation by moving logic into `maya/lib.py` --- colorbleed/maya/__init__.py | 51 +++++++++++++------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/colorbleed/maya/__init__.py b/colorbleed/maya/__init__.py index 8c861f8817..481a45692d 100644 --- a/colorbleed/maya/__init__.py +++ b/colorbleed/maya/__init__.py @@ -1,12 +1,13 @@ import os import logging +from functools import partial +from maya import utils from maya import cmds -from avalon import maya, io, api as avalon +from avalon import api as avalon from pyblish import api as pyblish - from . import menu from . import lib @@ -20,27 +21,16 @@ PUBLISH_PATH = os.path.join(PLUGINS_DIR, "maya", "publish") LOAD_PATH = os.path.join(PLUGINS_DIR, "maya", "load") CREATE_PATH = os.path.join(PLUGINS_DIR, "maya", "create") -LOAD_AT_START = ["AbcImport", "AbcExport", "mtoa"] - def install(): - pyblish.register_plugin_path(PUBLISH_PATH) avalon.register_plugin_path(avalon.Loader, LOAD_PATH) avalon.register_plugin_path(avalon.Creator, CREATE_PATH) menu.install() - # Add any needed plugins - for plugin in LOAD_AT_START: - log.info("Loading %s" % plugin) - if cmds.pluginInfo(plugin, query=True, loaded=True): - continue - cmds.loadPlugin(plugin, quiet=True) - log.info("Installing callbacks ... ") avalon.on("init", on_init) - avalon.on("new", on_new) avalon.on("save", on_save) @@ -55,19 +45,19 @@ def uninstall(): def on_init(_): avalon.logger.info("Running callback on init..") - maya.commands.reset_frame_range() - maya.commands.reset_resolution() + def force_load_deferred(plugin): + """Load a plug-in deferred so it runs after UI has initialized""" + try: + utils.executeDeferred(partial(cmds.loadPlugin, + plugin, + quiet=True)) + except RuntimeError, e: + log.warning("Can't load plug-in: " + "{0} - {1}".format(plugin, e)) - -def on_new(_): - avalon.logger.info("Running callback on new..") - - # Load dependencies - cmds.loadPlugin("AbcExport.mll", quiet=True) - cmds.loadPlugin("AbcImport.mll", quiet=True) - - maya.commands.reset_frame_range() - maya.commands.reset_resolution() + # Set up all plug-ins + for plugin in ["AbcImport", "AbcExport", "mtoa"]: + force_load_deferred(plugin) def on_save(_): @@ -78,13 +68,6 @@ def on_save(_): avalon.logger.info("Running callback on save..") + # Generate ids of the current context on nodes in the scene nodes = lib.get_id_required_nodes(referenced_nodes=False) - - # Lead with asset ID from the database - asset = os.environ["AVALON_ASSET"] - asset_id = io.find_one({"type": "asset", "name": asset}, - projection={"_id": True}) - - # generate the ids - for node in nodes: - lib.set_id(str(asset_id["_id"]), node) + lib.generate_ids(nodes)