aboutsummaryrefslogtreecommitdiff
path: root/plug-ins/ARTv2.py
blob: 97c930929502c86ebab4eb88740dffd9ad7d3a95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import os
import sys
import webbrowser

import maya.OpenMayaMPx as OpenMayaMPx
import maya.cmds as cmds
import maya.mel as mel

# maya 2016 and before vs maya 2017 and after
try:
    from PySide import QtCore
except:
    from PySide2 import QtCore


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
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()

    cmds.help(popupMode=True)
    return status


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Uninitialize the script plug-in
def uninitializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)