Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
Created November 20, 2015 11:45
Show Gist options
  • Save fredrikaverpil/7921a9981e906d7f893a to your computer and use it in GitHub Desktop.
Save fredrikaverpil/7921a9981e906d7f893a to your computer and use it in GitHub Desktop.
Chunk out .abc files from Maya
import os
import maya.cmds
def generateChunks( start, end, chunk_size ):
'''
Given a start, end and chunk size, spit out lists of frames.
'''
i = int(start)
while i < end:
chunk_range = range( i, i+int(chunk_size) )
yield chunk_range
i += chunk_size
# end def generateChunks
def run( start, end, out_path, chunk_size=1275 ):
'''
Perform actual Alembic export.
'''
# Define selected.
node_list = maya.cmds.ls( sl=True )
if not node_list:
raise Exception( 'Select node(s) to export in chunks.' )
selected = node_list[0]
chunk_num = 1
# Generate chunk list.
chunk_list = generateChunks( start, end, chunk_size )
# Maya scene file name
maya_scene_name = maya.cmds.file(q=True, sn=True, shn=True)
maya_scene_name = maya_scene_name.replace('.mb', '').replace('.ma', '')
# Define out directory.
out_dir = os.path.join(
out_path,
maya_scene_name
)
# Create dir, if it doesn't exist.
if not os.path.exists( out_dir ):
os.makedirs( out_dir )
# end if
# Iterate over chunks of frames.
for chunk in chunk_list:
print( 'Writing to chunk %s...' % chunk_num )
# Define file out.
file_out = os.path.join(
out_dir,
'%s_chunk%02d.abc' % (selected, chunk_num )
)
# Build Alembic job args.
alembic_job_args = [
'-frameRange %s %s' % (chunk[0], chunk[-1]),
'-uvWrite',
'-writeColorSets',
'-dataFormat ogawa',
'-root %s' % selected,
'-file %s' % file_out
]
# Run AbcExport command.
maya.cmds.AbcExport(
verbose=True,
jobArg=' '.join( alembic_job_args )
)
# Increment chunk.
chunk_num += 1
# end for
# end def run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment