Skip to content

Instantly share code, notes, and snippets.

@fereria
Last active January 4, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/caeef3306d64fc94f876 to your computer and use it in GitHub Desktop.
Save fereria/caeef3306d64fc94f876 to your computer and use it in GitHub Desktop.
## -*- coding: utf-8 -*-
import pymel.core as pm
import maya.cmds as mc
import maya.mel as mm
import os
import os.path
import re
def listAnimCurves(nodes):
animCurves = []
for node in nodes:
if node.nodeType() == "animCurveTL" or \
node.nodeType() == "animCurveTA" or \
node.nodeType() == "animCurveTU" or \
node.nodeType() == "animCurveTT" or \
node.nodeType() == "mute":
animCurves.append(node)
return animCurves
def animExport(fileName,pfx=None,flt=True):
saveDir = os.path.dirname(fileName)
basename = os.path.basename(fileName)
connections = []
animCurves = []
selected = pm.ls(sl=True,fl=True)
if len(selected) != 0:
connections = pm.listConnections(s=True,d=False)
animCurves = listAnimCurves(connections)
#dir作成
if os.path.exists(saveDir) != True:
os.makedirs(saveDir)
#eulerFilter
if flt == True:
pm.filterCurve(animCurves,filter="euler")
#アニメーションカーブを出力
pm.select(selected,r=True)
pm.exportSelectedAnim(fileName,type="mayaAscii",f=True)
cmds = []
#ノードのコネクション部分のmelコマンドを作成
for node in selected:
nodeConnections = node.listConnections(s=True,d=False,type="animCurve",p=True,c=True)
for connectAttr in nodeConnections:
srcAttr = connectAttr[1].name()
if pfx != None:
buff = connectAttr[0].name().split(":")
dstAttr = ":" + pfx + ":" + buff[len(buff)-1]
else:
dstAttr = ":" + connectAttr[0].name()
if re.search(".*\|.*",dstAttr) != None:
dstAttr = re.sub("\|","\|:",dstAttr)
cmds.append("connectAttr " + srcAttr + " " + dstAttr + ";")
#connectAttr を、出力したシーンに書き込み
with open(fileName,"a") as f:
for line in cmds:
f.write(line + "\n")
print "animExport " + fileName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment