# -*- coding: utf-8 -*- import os import sys import inspect import logging 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 Builder", 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, label="Pick-Walking Setup", c=launch_pickwalk_tool) 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="Reload All Scripts", c=reload_all_scripts) dev_menu = cmds.menuItem(parent=artv2_menu, subMenu=True, label="Development:") cmds.menuItem(parent=dev_menu, label="Run Tests", c=run_unit_tests) cmds.menuItem(parent=dev_menu, label="Joint Mover Markup", c=launch_markup_tools) cmds.menuItem(parent=dev_menu, label="Control Shape Tools", c=launch_control_manager) cmds.menuItem(parent=dev_menu, label="Get Reference Counts", c=get_reference_counts) 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 def create_new_rig(*args): """ Launches the art_rig_creator module, which aids and assists in creation of a rig.""" import artv2.tools.rigging.rig_builder.rig_builder_ui as art_rig_builder reload(art_rig_builder) art_rig_builder.show_window() # noinspection PyUnusedLocal 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 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 def launch_animation_tools(*args): """ Launches the art_animation_tools_ui tool, which houses the control picker and the animation tools""" raise NotImplementedError("{} not yet implemented.".format(launch_animation_tools.__name__)) # noinspection PyUnusedLocal 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 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 def launch_pickwalk_tool(*args): """ Launches the art_setup_pickwalk module, which allows the user to setup custom pick-walking for the rig.""" raise NotImplementedError("{} not yet implemented.".format(launch_pickwalk_tool.__name__)) # noinspection PyUnusedLocal 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 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 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 run_unit_tests(*args): """ Launches the UI for running unit tests""" import artv2.tools.system.artv2_tester.test_runner_ui as tester tester.run() # noinspection PyUnusedLocal def launch_markup_tools(*args): """ Launches the UI for marking up joint mover joints (rigging guides)""" import artv2.utilities.joint_mover_utilities as jm_utils jm_utils.show_window() # noinspection PyUnusedLocal def reload_all_scripts(*args): reset_session_for_script(SCRIPTS_PATH) reset_session_for_script(os.path.join(TOOLS_PATH, "tests")) def reset_session_for_script(user_path): """ Reloads all artv2 scripts""" user_path = user_path.lower() to_delete = [] for key, module in sys.modules.iteritems(): try: module_file_path = inspect.getfile(module).lower() if module_file_path.startswith(user_path): print "Removing %s" % key to_delete.append(key) except: pass for module in to_delete: del (sys.modules[module]) # noinspection PyUnusedLocal def get_reference_counts(*args): user_path = SCRIPTS_PATH.lower() for key, module in sys.modules.iteritems(): try: module_file_path = inspect.getfile(module).lower() if module_file_path.startswith(user_path): count = sys.getrefcount(key) print "{0}:\n\t\t{1} instances in memory".format(key, count) except: pass # noinspection PyUnusedLocal def launch_control_manager(*args): import artv2.utilities.control_utilities as cutils cutils.show_window() # 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, scripts, 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 + "/scripts")) 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, ["", "utilities", "rigging", "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 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 def uninitializePlugin(mobject): """ Boiler-plate function needed by Maya to uninitialize plugin.""" OpenMayaMPx.MFnPlugin(mobject)