-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiston_UI.py
114 lines (90 loc) · 3.5 KB
/
Piston_UI.py
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
import os
import pymel.core as pm
import maya.cmds as cmds
"""
This plugin is imported by Piston_plugin.py
It does generate the plugin shelf
Beware Maya crash when reloading th plugin, shelf commands change locations
and cause maya to crash.
"""
def abspath(path):
"""
Get the absolute path of icons images given the relative path to this file
:param path:
:return:
"""
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, path)
return filename
# Shelf icons paths
icons = {
'generatePiston': abspath('icons/generatePiston.png'),
'deleteNodes': abspath('icons/deleteNodes.png'),
'pistonSolverNode': abspath('icons/pistonSolverNode.png'),
'pistonVectorLength': abspath('icons/pistonVectorLengthNode.png'),
'flushUndo':abspath('icons/flushUndo.png')
}
# Buttons commands for the shelf
def generateCommand() :
pm.generatePiston()
def deletePluginNodes():
plugin_nodetypes = [
'pistonVectorLength',
'pistonNode'
]
for type in plugin_nodetypes:
nodes = pm.ls(type=type)
if nodes:
for i in range(len(nodes) - 1, -1, -1):
if pm.objExists(nodes[i]):
pm.delete(nodes[i])
print(type, ' : {} nodes deleted'.format(len(nodes)))
pm.flushUndo()
def createSolver():
pm.createNode('pistonNode')
def flushUndo():
pm.flushUndo()
def createVectorLength():
pm.createNode('pistonVectorLength')
# Generate the plugin Shelf
def generate_shelf():
# If the shelf exists delete it
if pm.shelfLayout('Piston plugin', exists=True):
print('Refreshing old shelf')
if pm.shelfLayout('Piston plugin', query=True, ca=True):
for each in pm.shelfLayout('Piston plugin', query=True, ca=True):
print(each)
pm.deleteUI(each)
pm.deleteUI('Piston_plugin')
# Create the shelf
plugin_shelf = pm.shelfLayout('Piston plugin', parent='ShelfLayout')
# Create the buttons on the shelf
pm.shelfButton(annotation='Generate a piston Rig :\n '
'Please, select start and end joint',
font='tinyBoldLabelFont',
command=generateCommand,
image=icons['generatePiston'],
style='iconAndTextCentered',
iol='AUTO',
parent=plugin_shelf)
pm.shelfButton(annotation='Delete all plugin nodetypes nodes',
command=deletePluginNodes,
image=icons['deleteNodes'],
iol ='CLEAN',
parent=plugin_shelf)
pm.shelfButton(annotation='flushUndo() command shortcut,\n'
'in order to avoid crash when reloading plugin',
command = flushUndo,
image=icons['flushUndo'],
iol='FLUSH',
parent=plugin_shelf)
pm.shelfButton(annotation='Create pistonSolver in node editor',
command=createSolver,
image=icons['pistonSolverNode'],
parent=plugin_shelf)
pm.shelfButton(annotation='Create a pistonVectorLength node in the node editor',
command=createVectorLength,
image=icons['pistonVectorLength'],
parent=plugin_shelf)
# button that create the rig
# button that delete all plugin-type nodes