-
Notifications
You must be signed in to change notification settings - Fork 1
/
animateExport.py
193 lines (157 loc) · 7.14 KB
/
animateExport.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
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
import pymel.core as pm
def animateExportUI():
winName = 'animateUI'
if(pm.window(winName,q=1,ex=1)):
pm.deleteUI(winName)
pm.window(winName,ret=1,mb=1)
pm.columnLayout('columnLayout8',adj=1)
pm.checkBoxGrp('exportType',ncb=3, label='export Type : ',
la3=[': transform', ': rotate', ': custom'])
pm.textFieldGrp('exportPath',l = 'export Path : ',adj = 0,
cl2 = ['right','center'],tx = 'asdd')
pm.button('export',c = 'animateExport()')
pm.showWindow(winName)
def animateExport():
trans = pm.checkBoxGrp('exportType',q = 1,v1 = 1)
rotate = pm.checkBoxGrp('exportType',q = 1,v2 = 1)
custom = pm.checkBoxGrp('exportType',q = 1,v3 = 1)
path = pm.textFieldGrp('exportPath',q = 1,tx = 1)
animExport(trans,rotate,custom,path)
def animExport(trans,rotate,custom,path):
#get all Ctrl
ctrlList = pm.ls(sl = 1)
print ctrlList
exportLocatorList = []
#prepare loc collect info
transformLocName = 'transform_AnimExport_Loc'
rotateLocName = 'rotate_AnimExport_Loc'
customLocName = 'custom_AnimExport_Loc'
#check loc
#trans Loc
if trans == 1:
if pm.objExists(transformLocName) == False:
transLoc = pm.spaceLocator(n = transformLocName)
exportLocatorList.append(transLoc)
#rotate Loc
if rotate == 1:
if pm.objExists(rotateLocName) == False:
rotateLoc = pm.spaceLocator(n = rotateLocName)
exportLocatorList.append(rotateLoc)
#custom Loc
if custom == 1:
if pm.objExists(customLocName) == False:
customLoc = pm.spaceLocator(n = customLocName)
exportLocatorList.append(customLoc)
if trans == 0 and rotate == 0 and custom == 0:
print 'plz select at least one kind of type'
for item in ('tx','ty','tz','rx','ry','rz','sx','sy','sz','v'):
if trans == 1:
pm.setAttr(transformLocName + '.' + item,l = 1,k = 0)
if rotate == 1:
pm.setAttr(rotateLocName + '.' + item,l = 1,k = 0)
if custom == 1:
pm.setAttr(customLocName + '.' + item,l = 1,k = 0)
##########
#get each ctrl
for ctrl in ctrlList:
#get keyable attr
allAttrList = pm.listAttr(ctrl,k = 1,u = 1,ud = 0)
baseAttrList = allAttrList
cusAttrList = pm.listAttr(ctrl,k = 1,u = 1,ud = 1)
for cusAttr in cusAttrList:
if cusAttr in baseAttrList:
baseAttrList.remove(cusAttr)
#print allAttrList
#print baseAttrList
#print cusAttrList
#print ctrl
for attr in baseAttrList:
#get connList
#print attr
connList = pm.listConnections(ctrl + '.' + attr,s = 1,d = 0)
#trans
if trans == 1:
if 'translate' in attr:
#print ctrl + '.' + attr
#print connList
if pm.objExists(transformLocName + '.' + ctrl + '_' + attr) == False:
pm.addAttr(transformLocName,ln = (ctrl + '_' + attr),at = 'double')
pm.setAttr(transformLocName + '.' + ctrl + '_' + attr,k = 1)
if connList == None:
pm.setAttr(transformLocName + '.' + ctrl + '_' + attr,
pm.getAttr(transformLocName + '.' + ctrl + '.' + attr))
#trans attr
else :
for conn in connList:
if 'animCurve' in pm.nodeType(conn):
print (ctrl + '.' + attr + ' has connection')
#print pm.objExists(transformLocName + ctrl + '_' + attr)
pm.connectAttr((conn + '.output'),(transformLocName + '.' + ctrl + '_' + attr),f = 1)
#rotate
if rotate == 1:
if 'rotate' in attr:
#print ctrl + '.' + attr
#print connList
if pm.objExists(rotateLocName + '.' + ctrl + '_' + attr) == False:
pm.addAttr(rotateLocName,ln = (ctrl + '_' + attr),at = 'double')
pm.setAttr(rotateLocName + '.' + ctrl + '_' + attr,k = 1)
if connList == None:
pm.setAttr(rotateLocName + '.' + ctrl + '_' + attr,
pm.getAttr(rotateLocName + '.' + ctrl + '.' + attr))
#rotate attr
else:
for conn in connList:
if 'animCurve' in pm.nodeType(conn):
print (ctrl + '.' + attr + ' has connection')
#print pm.objExists(rotateLocName + ctrl + '_' + attr)
pm.connectAttr((conn + '.output'),(rotateLocName + '.' + ctrl + '_' + attr),f = 1)
for attr in cusAttrList:
#get connList
#print attr
connList = pm.listConnections(ctrl + '.' + attr,s = 1,d = 0)
if pm.objExists(customLocName + '.' + ctrl + '_' + attr) == False:
pm.addAttr(customLocName,ln = (ctrl + '_' + attr),at = 'double')
pm.setAttr(customLocName + '.' + ctrl + '_' + attr,k = 1)
if connList == None:
pm.setAttr(customLocName + '.' + ctrl + '_' + attr,
pm.getAttr(customLocName + '.' + ctrl + '.' + attr))
#print ctrl + '.' + attr
#print connList
else:
#cus attr
if custom == 1:
for conn in connList:
if 'animCurve' in pm.nodeType(conn):
print (ctrl + '.' + attr + ' has connection')
#print pm.objExists(customLocName + ctrl + '_' + attr)
pm.connectAttr((conn + '.output'),(customLocName + '.' + ctrl + '_' + attr),f = 1)
pm.select(cl = 1)
for exportLoc in exportLocatorList:
pm.select(exportLoc,add = 1)
maya.cmds.file(path,f = 1,op = 'v = 0;',typ = 'mayaAscii',pr = 1,es = 1)
print 'drop Completed'
animateExportUI()
#
# import pymel.core as pm
# import maya.cmds as mc
# sels = pm.ls(sl = 1)
#
# print val
# print len(val)
#
#count ctrl
#create loc
#find time
#find inout angle
#key trans one by one
#
# for sel in sels:
# allAttr = pm.listAttr(sel,k = 1)
# for attr in allAttr:
# if 'translate' in attr:
# translate = attr
# keyCount = pm.keyframe(sel + '.' + translate,q = 1,kc=True)
# time = pm.keyframe(sel + '.' + translate,q = 1)
# value = pm.keyframe(sel + '.' + translate,q = 1, t = 1)
# val = pm.keyTangent(sels,t = (0,24),
# q = 1, at='translateY',outAngle = 1,inAngle = 1,itt = 1,ott = 1)