# -*- coding: utf-8 -*-
import os
import sys
from maya import cmds, mel, OpenMayaMPx
try:
from PySide import QtCore
from PySide import QtGui as QtWidgets
except ImportError:
from PySide2 import QtCore
from PySide2 import QtWidgets
SETTINGS = QtCore.QSettings("Jeremy Ernst", "artv2")
TOOLS_PATH = SETTINGS.value("tools_path")
SCRIPTS_PATH = SETTINGS.value("script_path")
def _create_artv2_menu():
""" Creates a menu on Maya's main menu bar for accessing various tools and features within artv2."""
maya_window = mel.eval('$temp1=$gMainWindow')
artv2_menu = cmds.menu("artv2_custom_menu", label="ART v2", parent=maya_window)
cmds.menuItem(parent=artv2_menu, label="Animation Rigging Toolkit 2.0", bld=True, enable=False)
cmds.menuItem(parent=artv2_menu, divider=True, dividerLabel="Rigging:")
cmds.menuItem(parent=artv2_menu, label="Rig Creator", c=create_new_rig)
cmds.menuItem(parent=artv2_menu, label="Edit Rig", c=edit_existing_rig)
cmds.menuItem(parent=artv2_menu, divider=True, dividerLabel="Animation:")
cmds.menuItem(parent=artv2_menu, label="Add Rig For Animation", c=add_rig_for_animation)
cmds.menuItem(parent=artv2_menu, label="Animation Tools", c=launch_animation_tools)
cmds.menuItem(parent=artv2_menu, divider=True, dividerLabel="Misc:")
cmds.menuItem(parent=artv2_menu, label="Settings", c=launch_settings_and_preferences)
cmds.menuItem(parent=artv2_menu, label="Hotkey Editor", c=launch_hotkey_editor)
cmds.menuItem(parent=artv2_menu, label="Pick-Walking Setup", c=launch_pickwalk_tool)
cmds.menuItem(parent=artv2_menu, divider=True, dividerLabel="Help:")
cmds.menuItem(parent=artv2_menu, label="Technical Documentation", c=launch_help_documentation)
cmds.menuItem(parent=artv2_menu, label="Check For Updates", c=check_for_updates)
cmds.menuItem(parent=artv2_menu, label="Report an Issue", c=launch_issue_reporter)
# noinspection PyUnusedLocal
[docs]def create_new_rig(*args):
""" Launches the art_rig_creator module, which aids and assists in creation of a rig."""
import artv2_rigging_tools.art_rig_creator as art_rig_creator
reload(art_rig_creator)
art_rig_creator.run()
# noinspection PyUnusedLocal
[docs]def edit_existing_rig(*args):
""" Launches the art_add_edit_rig_ui module, which in this case, opens the rig file for editing."""
raise NotImplementedError("{} not yet implemented.".format(edit_existing_rig.__name__))
# noinspection PyUnusedLocal
[docs]def add_rig_for_animation(*args):
""" Launches the art_add_edit_rig_ui module, which in this case, references in the rig file for animation."""
raise NotImplementedError("{} not yet implemented.".format(add_rig_for_animation.__name__))
# noinspection PyUnusedLocal
# noinspection PyUnusedLocal
[docs]def launch_settings_and_preferences(*args):
"""
Launches the art_settings module, which allows the user to change the tools directory, the scripts directory,
the icons directory, and the projects directory locations.
"""
raise NotImplementedError("{} not yet implemented.".format(launch_settings_and_preferences.__name__))
# noinspection PyUnusedLocal
[docs]def launch_hotkey_editor(*args):
"""
Launches the art_hotkey_editor module, which allows the user to bind keys to certain actions specific
to the animation and rigging tools.
"""
raise NotImplementedError("{} not yet implemented.".format(launch_hotkey_editor.__name__))
# noinspection PyUnusedLocal
# noinspection PyUnusedLocal
[docs]def check_for_updates(*args):
""" Launches the art_updater module, which will check for updates from the github repository."""
raise NotImplementedError("{} not yet implemented.".format(check_for_updates.__name__))
# noinspection PyUnusedLocal
[docs]def launch_issue_reporter(*args):
""" Launches the art_issue_reporter module, which gives an interface for posting issues to github."""
raise NotImplementedError("{} not yet implemented.".format(launch_issue_reporter.__name__))
# noinspection PyUnusedLocal
[docs]def launch_help_documentation(*args):
""" Loads the url for the online help documentation."""
raise NotImplementedError("{} not yet implemented.".format(launch_help_documentation.__name__))
# noinspection PyUnusedLocal
def _remove_custom_menu():
""" Removes the ARTv2 menu from Maya's main menu bar."""
cmds.deleteUI("artv2_custom_menu")
def _install_tools():
"""
Presents a QMessageBox prompting the user to locate the ARTv2 directory so Maya is aware of where the
tools are located.
"""
message_box = QtWidgets.QMessageBox()
message_box.setText("Error: Could not locate \"ARTv2\" directory.\n"
"Please locate the folder using the \"Browse\" button.")
message_box.setIcon(QtWidgets.QMessageBox.Warning)
message_box.addButton("Cancel", QtWidgets.QMessageBox.RejectRole)
message_box.addButton("Browse", QtWidgets.QMessageBox.ActionRole)
if message_box.exec_():
_browse()
def _browse():
"""
Opens a file dialog for the user to locate the ARTv2 directory. Once the directory is confirmed, QSettings are set
to record the different file paths for the base tools directory, and the icons, artv2_source, and projects directory.
"""
artv2_directory = cmds.fileDialog2(dialogStyle=2, fileMode=3)[0]
if not os.path.basename(artv2_directory).endswith("ARTv2"):
cmds.warning("Selected directory is not valid. Please locate the ARTv2 directory.")
return _browse()
SETTINGS.setValue("tools_path", os.path.normpath(artv2_directory))
SETTINGS.setValue("script_path", os.path.normpath(artv2_directory + "/artv2_source"))
SETTINGS.setValue("icon_path", os.path.normpath(artv2_directory + "/resources/icons"))
SETTINGS.setValue("project_path", os.path.normpath(artv2_directory + "/projects"))
global TOOLS_PATH, SCRIPTS_PATH
TOOLS_PATH = SETTINGS.value("tools_path")
SCRIPTS_PATH = SETTINGS.value("script_path")
_setup_tools()
def _setup_tools():
""" Adds the necessary paths to sys.path if the QSettings value for the tools_path exists."""
if not TOOLS_PATH:
_install_tools()
if not os.path.exists(TOOLS_PATH):
_install_tools()
return # Early return.
paths_to_add = map(_build_sys_path, ["", "artv2_utilities", "artv2_rigging_tools", "artv2_rig_modules",
"third_party"])
map(_add_system_paths, paths_to_add)
def _build_sys_path(path):
""" Construct a new path, appending the scripts directory with its passed-in sub-directories."""
return os.path.join(SCRIPTS_PATH, path)
def _add_system_paths(path):
""" Add the incoming path to sys.path."""
if os.path.normpath(path).replace("\\", "/") not in sys.path:
sys.path.append(path.replace("\\", "/"))
# noinspection PyPep8Naming
[docs]def initializePlugin(mobject):
""" Boiler-plate function needed by Maya to initialize plugin."""
mplugin = OpenMayaMPx.MFnPlugin(mobject, "Jeremy Ernst", "1.0")
status = mplugin.registerUI(_create_artv2_menu, _remove_custom_menu)
_setup_tools()
cmds.help(popupMode=True)
return status
# noinspection PyPep8Naming
[docs]def uninitializePlugin(mobject):
""" Boiler-plate function needed by Maya to uninitialize plugin."""
OpenMayaMPx.MFnPlugin(mobject)