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
|
"""
Author: Jeremy Ernst
"""
import maya.cmds as cmds
import System.interfaceUtils as interfaceUtils
import System.riggingUtils as riggingUtils
import System.utils as utils
from ThirdParty.Qt import QtGui, QtCore, QtWidgets
# maya 2016< maya2017> compatability
try:
import shiboken as shiboken
except:
import shiboken2 as shiboken
def getMainWindow():
"""
Returns a pointer to Maya's window as a QWidget.
"""
import maya.OpenMayaUI as mui
pointer = mui.MQtUtil.mainWindow()
# pyside QMainWindow takes in a QWidget rather than QObject
return shiboken.wrapInstance(long(pointer), QtWidgets.QWidget)
windowTitle = "Change Module Parent"
windowObject = "pyArtChangeModuleParentUi"
class ART_ChangeModuleParent_UI(QtWidgets.QMainWindow):
"""
This class allows the user to change the parent module bone of a given module. It is found within the
skeletonSettingsUI of an individual module in the Rig Creator.
.. image:: /images/changeModParent.png
"""
def __init__(self, currentParent, moduleInst, rigUiInst, parent=None):
"""
Instantiates the class, taking in current module information, and builds the interface.
:param currentParent: The current module parent bone of this module.
:param moduleInst: The instance in memory of the module whose name is to change.
:param rigUiInst: The instance in memory of the Rig Creator UI from which this class was called.
"""
super(ART_ChangeModuleParent_UI, self).__init__(parent)
# get the directory path of the tools
settings = QtCore.QSettings("Epic Games", "ARTv2")
self.toolsPath = settings.value("toolsPath")
self.iconsPath = settings.value("iconPath")
# create class variables
self.currentParent = currentParent
self.modInst = moduleInst
self.rigUiInst = rigUiInst
# load stylesheet
styleSheetFile = utils.returnNicePath(self.toolsPath, "Core/Scripts/Interfaces/StyleSheets/mainScheme.qss")
f = open(styleSheetFile, "r")
style = f.read()
f.close()
self.setStyleSheet(style)
# size policies
mainSizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
# create the main widget
self.mainWidget = QtWidgets.QWidget()
self.setCentralWidget(self.mainWidget)
# set qt object name
self.setObjectName(windowObject)
self.setWindowTitle(windowTitle)
# create the mainLayout for the rig creator UI
self.mainLayout = QtWidgets.QVBoxLayout(self.mainWidget)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.setSizePolicy(mainSizePolicy)
self.setMinimumSize(QtCore.QSize(250, 400))
self.setMaximumSize(QtCore.QSize(250, 400))
# create the background image
self.frame = QtWidgets.QFrame()
self.mainLayout.addWidget(self.frame)
self.frame.setObjectName("mid")
# create the layout for the widgets
self.widgetLayout = QtWidgets.QVBoxLayout(self.frame)
label = QtWidgets.QLabel("Choose New Parent:")
font = QtGui.QFont()
font.setBold(True)
label.setFont(font)
self.widgetLayout.addWidget(label)
self.boneSearch = QtWidgets.QLineEdit()
self.boneSearch.setPlaceholderText("Search..")
self.boneSearch.textChanged.connect(self.searchList)
self.widgetLayout.addWidget(self.boneSearch)
self.boneList = QtWidgets.QListWidget()
self.widgetLayout.addWidget(self.boneList)
self.boneList.setMinimumHeight(200)
# add items to comboBox
bones = utils.getViableParents()
# get our own bones
modBones = self.modInst.returnCreatedJoints
for bone in bones:
if bone not in modBones:
self.boneList.addItem(bone)
if bone == "root":
index = bones.index(bone)
self.boneList.setCurrentRow(index)
# update button
self.updateBtn = QtWidgets.QPushButton("UPDATE")
self.widgetLayout.addWidget(self.updateBtn)
self.updateBtn.setMinimumSize(QtCore.QSize(230, 40))
self.updateBtn.setMaximumSize(QtCore.QSize(230, 40))
self.updateBtn.setSizePolicy(mainSizePolicy)
font = QtGui.QFont()
font.setPointSize(12)
self.updateBtn.setFont(font)
self.updateBtn.setObjectName("blueButton")
# hookup signal/slot on create button
self.updateBtn.clicked.connect(self.applyModuleParentChange)
self.updateBtn.setFocus()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def searchList(self):
"""
Reads the text in the QLineEdit and searches the list widget for any items containing the search text,
hiding all listWidgetItems that do not contain the search text.
"""
searchText = self.boneSearch.text()
for i in range(self.boneList.count()):
lwItem = self.boneList.item(i)
if lwItem.text().find(searchText) != -1:
lwItem.setHidden(False)
else:
lwItem.setHidden(True)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def applyModuleParentChange(self):
"""
Gets the new parent from the selected ListWidgetItem text and then checks to make sure the selected parent
isn't a bone that is part of the module we're trying to change the parent on. Then updates text and attribute
values where needed.
.. note::
The following things get updated:
* Current Parent text item in the Skeleton Settings UI
* Network Node .parentModuleBone attribute
* Constrains nodes based on new parenting relationship
"""
# get new parent
newParent = self.boneList.currentItem().text()
# check to make sure new parent is not in this module's created bones list
createdBones = self.modInst.returnCreatedJoints
if newParent in createdBones:
cmds.confirmDialog(title="Error", icon="critical",
message="Cannot parent a module to a bone created by the module.")
return
# update current parent text
self.modInst.currentParent.setText(newParent)
# update network node parentModuleBone attribute
networkNode = self.modInst.returnNetworkNode
cmds.setAttr(networkNode + ".parentModuleBone", lock=False)
cmds.setAttr(networkNode + ".parentModuleBone", newParent, type="string", lock=True)
# delete the existing bone connection and reparent to the new parent and recreate the bone connection
if cmds.objExists(self.modInst.name + "_parentGrp"):
cmds.delete(self.modInst.name + "_parentGrp")
# parent under the new parent
moverGrp = cmds.getAttr(networkNode + ".moduleName")
moverGrp = moverGrp + "_mover_grp"
if newParent == "root":
mover = "root_mover"
offsetMover = "root_mover"
else:
networkNodes = utils.returnRigModules()
mover = utils.findMoverNodeFromJointName(networkNodes, newParent, False, True)
offsetMover = utils.findMoverNodeFromJointName(networkNodes, newParent)
# create the new bone representation
childMover = utils.findOffsetMoverFromName(self.modInst.name)
riggingUtils.createBoneConnection(offsetMover, childMover, self.modInst.name)
# delete the old constraint and create the new one
if cmds.objExists(self.modInst.name + "_mover_grp_parentConstraint*"):
cmds.delete(self.modInst.name + "_mover_grp_parentConstraint*")
networkNodes = utils.returnRigModules()
mover = utils.findMoverNodeFromJointName(networkNodes, newParent, False, True)
if mover is not None:
cmds.parentConstraint(mover, self.modInst.name + "_mover_grp", mo=True)
if cmds.objExists(self.modInst.name + "_mover_grp_scaleConstraint*"):
cmds.delete(self.modInst.name + "_mover_grp_scaleConstraint*")
if mover is not None:
cmds.scaleConstraint(mover, self.modInst.name + "_mover_grp", mo=True)
# delete the UI
mayaWindow = interfaceUtils.getMainWindow()
mayaWindow = mayaWindow.objectName()
cmds.deleteUI(mayaWindow + "|" + windowObject)
cmds.select(clear=True)
|