-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJointClass2.py
111 lines (72 loc) · 2.9 KB
/
JointClass2.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
import pymel.core as pm
b= pm.ls(sl=1)
c = cmds.ls(sl=1)
a = JointProc()
a.CtrJntEach(pm.ls(sl=1))
a.CtrJnt(pm.ls(sl=1))
class JointProc:
'''
use
'''
sel = pm.ls(sl=1)
pm.select(cl=1)
pm.select(sel)
cmdsSel = cmds.ls(sl=1)
pm.select(cl=1)
pivsList=[]
import pymel.core as pm
def __init__(self):
self.sel = pm.ls(sl=1)
def getSelection(self,Pivs = cmdsSel):
components = Pivs
selList = []
objName = components[0][0:components[0].index(".")]
# go through every component in the list. If it is a single component ("pCube1.vtx[1]"), add it to the list. Else,
# add each component in the index ("pCube1.vtx[1:5]") to the list
for c in components:
if ":" not in c:
selList.append(c)
else:
print c
startComponent = int(c[c.index("[") + 1: c.index(":")])
endComponent = int(c[c.index(":") + 1:c.index("]")])
componentType = c[c.index(".") + 1:c.index("[")]
while startComponent <= endComponent:
selList.append(objName + "." + componentType + "[" + str(startComponent) + "]")
startComponent += 1
return selList
pivsList.append(selList)
def CtrJnt(self,Piv=sel):
#createJoint
sl = Piv
try:
pm.select(sl)
tempPos = pm.cluster(n='Temp')[1]
Jnt = pm.createNode('joint',n = (sl[0]+'Jnt'))
pm.delete(pm.parentConstraint(tempPos,Jnt))
pm.delete(tempPos)
except:
tempPos = pm.createNode('transform',n = 'Temp')
pm.delete(pm.parentConstraint(sl,tempPos))
Jnt = pm.createNode('joint',n = (sl[0]+'_Jnt'))
pm.delete(pm.parentConstraint(tempPos,Jnt))
pm.delete(tempPos)
def CtrJntEach(self,cmdsSel):
#createJoint
try:
sl = getSelection()
#print sl
except:sl= cmdsSel
for i in sl:
try:
pm.select(i)
tempPos = pm.cluster(n='Temp')[1]
Jnt = pm.createNode('joint',n = (i+'Jnt'))
pm.delete(pm.parentConstraint(tempPos,Jnt))
pm.delete(tempPos)
except:
tempPos = pm.createNode('transform',n = 'Temp')
pm.delete(pm.parentConstraint(i,tempPos))
Jnt = pm.createNode('joint',n = (i+'_Jnt'))
pm.delete(pm.parentConstraint(tempPos,Jnt))
pm.delete(tempPos)