/
kmAnimImpExp.py
149 lines (129 loc) · 3.87 KB
/
kmAnimImpExp.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
# -*- coding: utf-8 -*-
###############################################################################
##
# @file kmAnimImpExp.py
# @brief AnimファイルとSelectファイル同時書き出し
# @version 1.0.1
# @date 2016/04/23
# @note - edit
# - cleanup
# @todo
#
###############################################################################
import os
import maya.cmds as mc
import maya.mel as mm
###############################################################################
if not mc.pluginInfo("animImportExport",q=True,loaded=True):
mc.loadPlugin( 'animImportExport' )
mc.pluginInfo( 'animImportExport', edit=True, autoload=True )
###############################################################################
def main():
mc.python('from kmAnimImpExp import *')
if mc.window( 'AnimImpExpUI', exists=True ):
mc.deleteUI('AnimImpExpUI')
WinName = mc.window(
'AnimImpExpUI',
title='Anim Import/Export with select',
iconName='AnimImpExpUI',
width=100,
height=200,
menuBar=True
)
mc.menu( label='Menu', tearOff=False )
mc.menuItem( label='Reload',command='from kmAnimImpExp import *;main()')
mc.menuItem( divider=True )
mc.menuItem( label='Quit' )
mc.columnLayout(adj=True)
mc.button(label='Import Anim',command='kmAnimImp()')
mc.button(label='Export Anim',command='kmAnimExp()')
mc.setParent('..') #columnLayout
mc.showWindow(WinName)
###############################################################################
##
# @brief Brief
#
# @return Return_Description
#
# @details Details
#
def kmAnimImp():
#select controllers
strAnimFile = kmAnimFilePath( 1, 'animImport(*.anim)', 'anim', 'Load Key Animation')
if strAnimFile == '':
return
strSelectFile = strAnimFile.replace('.anim', '.mel')
mm.eval('source "' + strSelectFile + '";')
mc.file(
strAnimFile,
force=True,
type='animImport',
i=True,
ignoreVersion=True,
renameAll=True,
options='targetTime=4;option=replace;connect=0'
)
###############################################################################
##
# @brief Brief
#
# @return Return_Description
#
# @details Details
#
def kmAnimExp():
#get export full path
strAnimFile = kmAnimFilePath(0, ('animExport(*.anim)'), 'anim', 'Save Key Animation')
if strAnimFile == '':
return
strSelectFile = strAnimFile.replace('.anim','.mel')
#get range
iStart = mc.playbackOptions(q=True,min=True)
iEnd = mc.playbackOptions(q=True,max=True)
#export animFile
mc.file(
strAnimFile,
force=True,
exportSelectedAnim=True,
type='animExport',
options=('options=keys;hierarchy=none;precision=8;intValue=17;nodeNames=1;verboseUnits=0;whichRange=1;range='+str(iStart)+':'+str(iEnd)+';'+'helpPictures=0;useChannelBox=0;controlPoints=0;shapes=0;copyKeyCmd=-animation objects -option keys -hierarchy none -controlPoints 0 -shape 0')
)
# #expor select file
kmExportSelects(strSelectFile)
###############################################################################
##
# @brief Brief
#
# @param [in] iFileMode
# @param [in] strFileFilter ex) 'nimImport(*.anim)
# @param [in] strSelectFilter ex) anim
# @param [in] strCaption window title
# @return Return_Description
#
# @details Details
#
def kmAnimFilePath( iFileMode, strFileFilter, strSelectFilter, strCaption):
strlPath = []
strlPath = mc.fileDialog2(
fileMode=iFileMode,
fileFilter=strFileFilter,
selectFileFilter=strSelectFilter,
dialogStyle=2,
caption=strCaption
)
try:
if len(strlPath) > 0:
return strlPath[0]
except:
return ''
###############################################################################
def kmExportSelects( strFullPath ):
strlData = []
strlData = mc.ls(sl=True)
strlData.insert(0, 'select -r')
strlData.append(';')
strData = '\r\n'.join(strlData)
f = open(strFullPath, 'w')
f.write(strData)
f.close()
###############################################################################