Skip to content

Instantly share code, notes, and snippets.

@Roumenov
Last active October 25, 2019 07:50
Show Gist options
  • Save Roumenov/e4991385604be1d0fd2e7579fe72a00b to your computer and use it in GitHub Desktop.
Save Roumenov/e4991385604be1d0fd2e7579fe72a00b to your computer and use it in GitHub Desktop.
import pymel.core as pm
import maya.cmds as cmds
#Version: 1.1.2
#declaring initial variables
#global playStartTime
#global playEndTime
def ab_getFile():
global outputFile
testFile = cmds.file(q = True, sn = True)
print "current file:"
print testFile
testFile = testFile.replace('.ma','.fbx')
if '/latest' in testFile:
print "Sylvia"
testFileA = testFile.split('/latest')[0]
testFileB = testFile.split('/latest')[1]
outputFile = testFileA + '/export' + testFileB
print outputFile
elif '/Owl/' in testFile:
print "owl"
testFileA = testFile.split('/Owl/')[0]
testFileB = testFile.split('/Owl/')[1]
outputFile = testFileA + '/Owl/export/' + testFileB
print outputFile
elif '/Quinn/' in testFile:
print "Quinn"
testFileA = testFile.split('/Quinn/')[0]
testFileB = testFile.split('/Quinn/')[1]
outputFile = testFileA + '/Quinn/export/' + testFileB
print outputFile
elif '/Knight/' in testFile:
print "Knight"
testFileA = testFile.split('/Knight/')[0]
testFileB = testFile.split('/Knight/')[1]
outputFile = testFileA + '/Knight/export/' + testFileB
print outputFile
elif '/Roxanne/' in testFile:
print "Roxanne"
testFileA = testFile.split('/Roxanne/')[0]
testFileB = testFile.split('/Roxanne/')[1]
outputFile = testFileA + '/Roxanne/export/' + testFileB
print outputFile
else:
print "other"
outputFile = testFile
print outputFile
#PURPOSE import all referenced scenes
#PROCEDURE list pymel references, looop
#PRESUMPTION references are only one reference deep, and right now we really only have one
def ab_importReferences():
done = False
refs = pm.listReferences()
totalRefs = len(refs)
if len(refs) == 0:
print "no references to import"
return False
else:
while (done == False and (len(refs) != 0)):
refs = pm.listReferences()
print ("importing ", len(refs), " references....")
for ref in refs:
if ref.isLoaded():
done = False
#ref.importContents()
ref.importContents(removeNamespace = True) #---- remove namespace doesn't seem to work
else:
done = True
print ("Imported " + str(totalRefs) + " references")
return True
#def ab_setTimeline(auto,startVal= 0,endVal = 0): eventually add these option flags
def ab_setTimeline():
global playStartTime
global playEndTime
playStartTime = pm.playbackOptions(query = True, minTime = True)
playEndTime = pm.playbackOptions(query = True, maxTime = True)
playStartTime = int(playStartTime)
playEndTime = int(playEndTime)
#PURPOSE set up basic selections for baking, exporting, and any other procedures that need a direct reference to scene objects
#PROCEDURE
#PRESUMPTION user is selecting a node in the hierarchy of the rig they intend to export, names have not been imported
def tag_root(tag = False,target = None): ## ---- upgrade to use attr, need to distinguish the character somehow....
if tag:
pm.select(target)
rootNode = pm.selected()[0].root()
pm.select(clear = True)
if rootNode.hasAttr("exportRoot"):
print('success!')
else:
pm.addAttr(rootNode, longName = 'exportRoot', attributeType = 'message')
print('fail')
#rigRootName = rootNode.name() + "Set"
#rootNode = pm.sets(name = rigRootName)
return rootNode
#query .sets to get the name
else:
rootNode == pm.ls('*.exportRoot', objectsOnly = True)
return rootNode
#rigRootName = rootNode.name() + "Set"
#rootNode = pm.sets(name = rigRootName)
# pm.select(root)
# Should change this later to take the prefix as an argument.
#PRESUMPTIONS prefix takes the form of a single character followed by '_' x_ Any other order will break shit.
#PRESUMPTIONS prefix will be one character followed by an underscore and nothing has happened to the name since import
def ab_removePrefix(inputString):
sceneList = pm.ls()
for item in sceneList:
itemString = item.shortName()
if itemString.startswith(inputString):
itemName = itemString.split("_", 1)[1]
pm.rename(item, itemName)
else:
pass
def ab_bakeAnimation(*bakeList):#changed to list input
#pm.select(bakeTarget)
#Bake Animation
for target in bakeList:
pm.bakeResults(target, simulation = 1, sampleBy = 1, pok = 1, sac = 0, time = (playStartTime, playEndTime))
def ab_fileExport(arg):
pm.select(arg)
cmds.file(outputFile, exportSelected=True, type="FBX export")
####==== ======== ====####
#
# ACTION ZONE!!!!
#
####==== ======== ====####
def ab_pnomExport():
if len(pm.ls(sl=1)):
root = tag_root(tag = True, target = pm.ls(selection = True)[0])
ab_getFile()
ab_setTimeline()
ab_importReferences()
print('refs imported')
pm.select("bakeSet", replace = True)
bakeSet = pm.ls(sl=1)
pm.select("deleteSet", replace = True)
deleteSet = pm.ls(sl=1)
ab_bakeAnimation(bakeSet)
print('bake')
pm.delete(deleteSet)
print('deleted crap')
ab_fileExport(root)
else:
pm.warning('no rig selected')
ab_pnomExport()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment