diff options
| author | home_pc <[email protected]> | 2020-01-20 13:48:51 -0800 |
|---|---|---|
| committer | home_pc <[email protected]> | 2020-01-20 13:48:51 -0800 |
| commit | 75fa1d1810e98453960a81115d88302e276d817f (patch) | |
| tree | 92f37accb3cb041d056d00525b5830a69862631a /plug-ins/ARTv2.py | |
| parent | fixed install.mel issue (diff) | |
| download | artv2-75fa1d1810e98453960a81115d88302e276d817f.tar.xz artv2-75fa1d1810e98453960a81115d88302e276d817f.zip | |
Uploading work on refactor
At this point, all components can build their skeletons. Next steps are to get components building their rigs.
Diffstat (limited to 'plug-ins/ARTv2.py')
| -rw-r--r-- | plug-ins/ARTv2.py | 523 |
1 files changed, 247 insertions, 276 deletions
diff --git a/plug-ins/ARTv2.py b/plug-ins/ARTv2.py index 97c9309..200fb52 100644 --- a/plug-ins/ARTv2.py +++ b/plug-ins/ARTv2.py @@ -1,292 +1,263 @@ +# -*- coding: utf-8 -*- + import os import sys -import webbrowser +import inspect +import logging -import maya.OpenMayaMPx as OpenMayaMPx -import maya.cmds as cmds -import maya.mel as mel +from maya import cmds, mel, OpenMayaMPx -# maya 2016 and before vs maya 2017 and after try: from PySide import QtCore -except: + 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() -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def makeMyCustomUI(): - gMainWindow = mel.eval('$temp1=$gMainWindow') - customMenu = cmds.menu("epicGamesARTv2Menu", label="A.R.T. 2.0", parent=gMainWindow) - - # ART - cmds.menuItem(parent=customMenu, label="Animation Rigging Toolkit 2.0", bld=True, enable=False) - - cmds.menuItem(parent=customMenu, divider=True, dividerLabel="Rigging:") - cmds.menuItem(parent=customMenu, label="Rig Creator", c=ART_characterRigCreator) - cmds.menuItem(parent=customMenu, label="Edit Rig", c=ART_EditRig) - - cmds.menuItem(parent=customMenu, divider=True, dividerLabel="Animation:") - cmds.menuItem(parent=customMenu, label="Add Rig For Animation", c=ART_AddRig) - cmds.menuItem(parent=customMenu, label="Animation Tools", c=ART_LaunchAnimTools) - - cmds.menuItem(parent=customMenu, divider=True, dividerLabel="Misc:") - cmds.menuItem(parent=customMenu, label="Settings", c=launchSettings) - # cmds.menuItem(parent=customMenu, label="Check For Updates", c=ART_Update) - # cmds.menuItem(parent=customMenu, label="Report an Issue", c=ART_Report) - - cmds.menuItem(parent=customMenu, divider=True, dividerLabel="Help") - cmds.menuItem(parent=customMenu, label="Technical Documentation", c=ART_TechDocs) - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_writeStyleSheets(*args): - import System.utils as utils - reload(utils) - - import System.interfaceUtils as interfaceUtils - reload(interfaceUtils) - - settings = QtCore.QSettings("Epic Games", "ARTv2") - scriptPath = settings.value("scriptPAth") - stylesheetDir = utils.returnNicePath(scriptPath, "Interfaces/StyleSheets/") - stylesheets = os.listdir(stylesheetDir) - - for sheet in stylesheets: - interfaceUtils.writeQSS(os.path.join(stylesheetDir, sheet)) - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_characterRigCreator(*args): - ART_writeStyleSheets() - import Interfaces.ART_RigCreatorUI as ART_RigCreatorUI - reload(ART_RigCreatorUI) - ART_RigCreatorUI.createUI() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_EditRig(*args): - ART_writeStyleSheets() - import Interfaces.ART_EditRigUI as ART_EditRigUI - ART_EditRigUI.run() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_AddRig(*args): - ART_writeStyleSheets() - import Interfaces.ART_EditRigUI as ART_EditRigUI - ART_EditRigUI.runAdd() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_LaunchAnimTools(*args): - ART_writeStyleSheets() - import Interfaces.ART_AnimationUI as ART_AnimationUI - reload(ART_AnimationUI) - ART_AnimationUI.run() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def launchSettings(*args): - ART_writeStyleSheets() - import System.ART_Settings as ART_Settings - ART_Settings.run() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_Update(*args): - ART_writeStyleSheets() - import System.ART_Updater as ART_Updater - ART_Updater.run() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_Report(*args): - ART_writeStyleSheets() - import System.ART_Reporter as ART_Reporter - ART_Reporter.run() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def ART_TechDocs(*args): - settings = QtCore.QSettings("Epic Games", "ARTv2") - toolsPath = settings.value("toolsPath") - html_file = os.path.join(toolsPath, "Documentation\\build\\index.html") - webbrowser.get().open('file://' + os.path.realpath(html_file)) - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -def removeMyCustomUI(): - cmds.deleteUI("epicGamesARTv2Menu") - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - -# Function for allowing user to browse to Maya Tools directory location -def epicToolsInstall_UI(): - if cmds.window("epicToolsInstall_UI", exists=True): - cmds.deleteUI("epicToolsInstall_UI") - - window = cmds.window("epicToolsInstall_UI", w=300, h=100, title="Epic Games Tools Install", mnb=False, mxb=False) - - mainLayout = cmds.columnLayout(w=300, h=100) - formLayout = cmds.formLayout(w=300, h=100) - - text = cmds.text( - label="ERROR: Could not find Maya Tools directory.\n Please locate folder using the \'Browse\' button.", w=300) - cancelButton = cmds.button(label="Cancel", w=140, h=50, c=cancel) - browseButton = cmds.button(label="Browse", w=140, h=50, c=browse) - - cmds.formLayout(formLayout, edit=True, af=[(text, 'left', 10), (text, 'top', 10)]) - cmds.formLayout(formLayout, edit=True, af=[(cancelButton, 'left', 5), (cancelButton, 'top', 50)]) - cmds.formLayout(formLayout, edit=True, af=[(browseButton, 'right', 5), (browseButton, 'top', 50)]) - - cmds.showWindow(window) - cmds.window(window, edit=True, w=300, h=100) - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# if user cancels out of UI setup -def cancel(*args): - cmds.deleteUI("epicToolsInstall_UI") - cmds.warning("Maya Tools will not be setup") - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# function to browse to MayaTools location on disk -def browse(*args): - # browser to tools directory - mayaToolsDir = cmds.fileDialog2(dialogStyle=2, fileMode=3)[0] - # confirm that this is actually the maya tools directory - if os.path.basename(mayaToolsDir) != "ARTv2": - cmds.warning("Selected directory is not valid. Please locate the ARTv2 directory or ensure the directory is named 'ARTv2'.") - - else: - cmds.deleteUI("epicToolsInstall_UI") - - # create file that contains this path - settings = QtCore.QSettings("Epic Games", "ARTv2") - settings.setValue("toolsPath", os.path.normpath(mayaToolsDir)) - settings.setValue("scriptPath", os.path.normpath(mayaToolsDir + "/Core/Scripts")) - settings.setValue("iconPath", os.path.normpath(mayaToolsDir + "/Core/Icons")) - settings.setValue("projectPath", os.path.normpath(mayaToolsDir + "/Projects")) - - # run setup - epicTools() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# check to see if tools exist -def epicTools(): - settings = QtCore.QSettings("Epic Games", "ARTv2") - toolsPath = settings.value("toolsPath") - scriptPath = settings.value("scriptPath") - iconPath = settings.value("iconPath") - projectPath = settings.value("projectPath") - - if toolsPath == None: - epicToolsInstall_UI() - - if os.path.exists(toolsPath): - paths = [returnFriendlyPath(scriptPath), - returnFriendlyPath(os.path.join(scriptPath, os.path.normpath("System"))), - returnFriendlyPath(os.path.join(scriptPath, os.path.normpath("Interfaces"))), - returnFriendlyPath(os.path.join(scriptPath, os.path.normpath("RigModules"))), - returnFriendlyPath(os.path.join(scriptPath, os.path.normpath("ThirdParty")))] - defaultPaths = [returnFriendlyPath(os.path.join(toolsPath, os.path.normpath("Core/Scripts"))), - returnFriendlyPath(os.path.join(toolsPath, os.path.normpath("Core/Scripts/System"))), - returnFriendlyPath(os.path.join(toolsPath, os.path.normpath("Core/Scripts/Interfaces"))), - returnFriendlyPath(os.path.join(toolsPath, os.path.normpath("Core/Scripts/RigModules"))), - returnFriendlyPath(os.path.join(toolsPath, os.path.normpath("Core/Scripts/ThirdParty")))] - - # look in sys.path to see if path is in sys.path. if not, add it - for path in defaultPaths: - for sysPath in sys.path: - sysPath = returnFriendlyPath(sysPath) - if path == sysPath: - sys.path.remove(path) - - for path in paths: - if not path in sys.path: - sys.path.append(path) - - else: - epicToolsInstall_UI() - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# convenience function for returning an os friendly path -def returnFriendlyPath(path): - nicePath = os.path.normpath(path) - if nicePath.partition("\\")[2] != "": - nicePath = nicePath.replace("\\", "/") - return nicePath - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Initialize the script plug-in -def initializePlugin(mobject): - mplugin = OpenMayaMPx.MFnPlugin(mobject, "Jeremy Ernst\nEpic Games, Inc.", "1.0") - status = mplugin.registerUI(makeMyCustomUI, removeMyCustomUI) - # check for tools path - epicTools() +# 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 -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Uninitialize the script plug-in +# noinspection PyPep8Naming def uninitializePlugin(mobject): - mplugin = OpenMayaMPx.MFnPlugin(mobject) + """ Boiler-plate function needed by Maya to uninitialize plugin.""" + OpenMayaMPx.MFnPlugin(mobject) |