def export_alembic_from_cache_node(handles=0, step=1):
    """exports alembic caches by looking at the current scene and try to find
    transform nodes which has an attribute called "cacheable"

    :param int handles: An integer that shows the desired handles from start
      and end.
    """
    import os

    # get cacheable nodes in the current scene
    cacheable_nodes = get_cacheable_nodes()

    # stop if there are no cacheable nodes in the scene
    if not cacheable_nodes:
        return

    # load Abc plugin first
    if not pm.pluginInfo('AbcExport', q=1, l=1):
        pm.loadPlugin('AbcExport')

    from anima.ui.progress_dialog import ProgressDialogManager
    pdm = ProgressDialogManager()

    cacheable_nodes.sort(key=lambda x: x.getAttr('cacheable'))

    caller = pdm.register(len(cacheable_nodes), 'Exporting Alembic Caches')

    start_frame = pm.playbackOptions(q=1, ast=1)
    end_frame = pm.playbackOptions(q=1, aet=1)

    current_file_full_path = pm.sceneName()
    current_file_path = os.path.dirname(current_file_full_path)
    current_file_name = os.path.basename(current_file_full_path)

    # export alembic caches
    previous_cacheable_attr_value = ''
    i = 1
    for cacheable_node in cacheable_nodes:
        cacheable_attr_value = cacheable_node.getAttr('cacheable')
        if cacheable_attr_value == previous_cacheable_attr_value:
            i += 1
        else:
            i = 1

        # hide any child node that has "rig" or "proxy" or "low" in its name
        wrong_node_names = ['rig', 'proxy', 'low']
        hidden_nodes = []
        for child in pm.ls(cacheable_node.getChildren(), type='transform'):
            if any([n in child.name().split(':')[-1].lower() for n in wrong_node_names]):
                if child.v.get() is True and not child.v.isLocked():
                    child.v.set(False)
                    hidden_nodes.append(child)

        output_path = os.path.join(
            current_file_path,
            'Outputs/alembic/%s%i/' % (cacheable_attr_value, i)
        )

        output_filename = '%s_%i_%i_%s%i%s' % (
            os.path.splitext(current_file_name)[0],
            start_frame, end_frame, cacheable_attr_value, i, '.abc'
        )

        output_full_path = \
            os.path.join(output_path, output_filename).replace('\\', '/')
        try:
            os.makedirs(os.path.dirname(output_full_path))
        except __HOLE__:
            pass

        command = 'AbcExport -j "-frameRange %s %s -step %s -ro ' \
                  '-stripNamespaces -uvWrite -worldSpace -eulerFilter ' \
                  '-writeVisibility -root %s -file %s";'

        # use a temp file to export the cache
        # and then move it in to place
        temp_cache_file_path = \
            tempfile.mktemp(suffix='.abc').replace('\\', '/')

        pm.mel.eval(
            command % (
                int(start_frame - handles),
                int(end_frame + handles),
                step,
                cacheable_node.fullPath(),
                temp_cache_file_path
            )
        )
        # move in to place
        shutil.move(temp_cache_file_path, output_full_path)

        previous_cacheable_attr_value = cacheable_attr_value

        # reveal any previously hidden nodes
        for node in hidden_nodes:
            node.v.set(True)

        caller.step()


# noinspection PyStatementEffect
dataset/ETHPy150Open eoyilmaz/anima/anima/env/mayaEnv/auxiliary.py/export_alembic_from_cache_node