#NEWLINE# def export_alembic_from_cache_node( handles = 0 , step = 1 ) : #NEWLINE# #INDENT# 'exports alembic caches by looking at the current scene and try to find\n    transform nodes which has an attribute called "cacheable"\n\n    :param int handles: An integer that shows the desired handles from start\n      and end.\n    ' #NEWLINE# import os #NEWLINE# cacheable_nodes = get_cacheable_nodes ( ) #NEWLINE# if ( not cacheable_nodes ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( not pm . pluginInfo ( 'AbcExport' , q = 1 , l = 1 ) ) : #NEWLINE# #INDENT# pm . loadPlugin ( 'AbcExport' ) #NEWLINE# #UNINDENT# from anima.ui.progress_dialog import ProgressDialogManager #NEWLINE# pdm = ProgressDialogManager ( ) #NEWLINE# cacheable_nodes . sort ( key = ( lambda x : x . getAttr ( 'cacheable' ) ) ) #NEWLINE# caller = pdm . register ( len ( cacheable_nodes ) , 'Exporting Alembic Caches' ) #NEWLINE# start_frame = pm . playbackOptions ( q = 1 , ast = 1 ) #NEWLINE# end_frame = pm . playbackOptions ( q = 1 , aet = 1 ) #NEWLINE# current_file_full_path = pm . sceneName ( ) #NEWLINE# current_file_path = os . path . dirname ( current_file_full_path ) #NEWLINE# current_file_name = os . path . basename ( current_file_full_path ) #NEWLINE# previous_cacheable_attr_value = '' #NEWLINE# i = 1 #NEWLINE# for cacheable_node in cacheable_nodes : #NEWLINE# #INDENT# cacheable_attr_value = cacheable_node . getAttr ( 'cacheable' ) #NEWLINE# if ( cacheable_attr_value == previous_cacheable_attr_value ) : #NEWLINE# #INDENT# i += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i = 1 #NEWLINE# #UNINDENT# wrong_node_names = [ 'rig' , 'proxy' , 'low' ] #NEWLINE# hidden_nodes = [ ] #NEWLINE# for child in pm . ls ( cacheable_node . getChildren ( ) , type = 'transform' ) : #NEWLINE# #INDENT# if any ( [ ( n in child . name ( ) . split ( ':' ) [ ( - 1 ) ] . lower ( ) ) for n in wrong_node_names ] ) : #NEWLINE# #INDENT# if ( ( child . v . get ( ) is True ) and ( not child . v . isLocked ( ) ) ) : #NEWLINE# #INDENT# child . v . set ( False ) #NEWLINE# hidden_nodes . append ( child ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# output_path = os . path . join ( current_file_path , ( 'Outputs/alembic/%s%i/' % ( cacheable_attr_value , i ) ) ) #NEWLINE# output_filename = ( '%s_%i_%i_%s%i%s' % ( os . path . splitext ( current_file_name ) [ 0 ] , start_frame , end_frame , cacheable_attr_value , i , '.abc' ) ) #NEWLINE# output_full_path = os . path . join ( output_path , output_filename ) . replace ( '\\' , '/' ) #NEWLINE# try : #NEWLINE# #INDENT# os . makedirs ( os . path . dirname ( output_full_path ) ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# command = 'AbcExport -j "-frameRange %s %s -step %s -ro -stripNamespaces -uvWrite -worldSpace -eulerFilter -writeVisibility -root %s -file %s";' #NEWLINE# temp_cache_file_path = tempfile . mktemp ( suffix = '.abc' ) . replace ( '\\' , '/' ) #NEWLINE# pm . mel . eval ( ( command % ( int ( ( start_frame - handles ) ) , int ( ( end_frame + handles ) ) , step , cacheable_node . fullPath ( ) , temp_cache_file_path ) ) ) #NEWLINE# shutil . move ( temp_cache_file_path , output_full_path ) #NEWLINE# previous_cacheable_attr_value = cacheable_attr_value #NEWLINE# for node in hidden_nodes : #NEWLINE# #INDENT# node . v . set ( True ) #NEWLINE# #UNINDENT# caller . step ( )