Created
June 15, 2022 07:11
-
-
Save zclongpop123/585a92c8fe4f39646fe3bf566ce8d8fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#======================================== | |
# author: Changlong.Zang | |
# mail: [email protected] | |
# time: Wed Jun 15 15:11:51 2022 | |
#======================================== | |
import os | |
import glob | |
from datetime import datetime | |
import maya.cmds as mc | |
import maya.mel as mel | |
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | |
EXPORT_GROUPS = ('MODEL', ) | |
EXPORT_ARGS = '-stripNamespaces -uvWrite -writeUVSets -worldSpace -writeVisibility -dataFormat ogawa' | |
PRE_FRAME_OFFSET = 5 | |
POST_FRAME_OFFSET = 5 | |
def export_alembic(cache_dir, log): | |
''' | |
''' | |
#- | |
if not mc.pluginInfo('AbcExport.mll', q=True, loaded=True): | |
try: | |
mc.loadPlugin('AbcExport.mll', quiet=True) | |
except: | |
return False | |
start_frame = int(mc.playbackOptions(q=True, min=True) - PRE_FRAME_OFFSET) | |
end_frame = int(mc.playbackOptions(q=True, max=True) + POST_FRAME_OFFSET) | |
export_cmds = 'AbcExport' | |
for ref in mc.file(q=True, r=True): | |
ns = mc.file(ref, q=True, ns=True) | |
export_objects = ['{0}:{1}'.format(ns, geo) for geo in EXPORT_GROUPS] | |
export_objects = [geo for geo in export_objects if mc.objExists(geo)] | |
if not export_objects: | |
continue | |
cache_file = os.path.join(cache_dir, '{0}.abc'.format(ns)).replace('\\', '/') | |
export_cmds += ' -j "-frameRange {0} {1} {2} -root {3} -file {4}"'.format(start_frame, | |
end_frame, | |
EXPORT_ARGS, | |
' -root '.join(export_objects), | |
cache_file) | |
with open(log, 'w') as f: | |
f.write(export_cmds) | |
mel.eval(export_cmds) | |
def main(pattrn): | |
''' | |
''' | |
shot_files = dict() | |
for f in glob.glob(pattrn): | |
shot_files.setdefault(os.path.dirname(f), list()).append(f) | |
for files in shot_files.values(): | |
scene = sorted(files)[-1] | |
log = '{0}.{1}.log'.format(scene, datetime.now().strftime('%Y-%m-%d')) | |
if os.path.isfile(log): | |
continue | |
with open(log, 'w') as f: | |
f.write(datetime.now().strftime('%Y-%m-%d %H:%M:%S')) | |
f.write('\r\n') | |
mc.file(scene, o=True, f=True, pmt=False) | |
export_alembic('D:/test', log) | |
mc.file(new=True, f=True) | |
if __name__ == '__main__': | |
main('D:/*.m[ab]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment