src/bvhtoolbox/manipulate/removeframes.py
def remove_frames(file_path, start, end=None, dst_file=None):
    """Delete frames in BVH file from start to end or to the end of file.

    :param file_path: BVH file to delete frames from.
    :type file_path: str
    :param start: First frame to be deleted. Frame count starts with 1.
    :type start: int
    :param end: Last frame to be deleted. If None, all frames after start are removed.
    :type end: int
    :param dst_file: If you want to save to a new file, specify its path.
    :type dst_file: str
    :return: Whether the file could be processed and saved.
    :rtype: bool
    """
    # Sanity Check on start and end.
    if end and (start >= end):
        print("First frame to remove is greater than last frame to remove. Aborting.\n"
              "File: {]".format(file_path))
        return False

    file_type = os.path.splitext(file_path)[1].lower()
    if file_type != ".bvh":
        print("ERROR: File extension BVH expected for: {}".format(file_path))
        return False

    try:
        with open(file_path, mode='r') as file_handle:
            lines = file_handle.readlines()
    except FileNotFoundError:
        print("ERROR: file {} not found".format(file_path))
        return False

    # Find first frame.
    frames_idx = lines.index(next(line for line in lines if line.startswith('Frames:')))
    frame1_idx = frames_idx + 2

    # Slice together the parts we want to keep.
    if end:
        lines = lines[:start + frame1_idx - 1] + lines[end + frame1_idx:]
    else:
        lines = lines[:start + frame1_idx - 1]

    # We need to update Frames:
    num_frames = len(lines[frame1_idx:])
    lines[frames_idx] = "Frames: {}\n".format(num_frames)

    # If no destination file is specified, overwrite input file.
    if not dst_file:
        dst_file = file_path
    try:
        with open(dst_file, mode='w') as file_handle:
            file_handle.writelines(lines)
    except OSError:
        print("ERROR: Can't write to destination {}".format(dst_file))
        return False
    # If we reached this point, everything went well.
    return True
Delete frames in BVH file from start to end or to the end of file.

    :param file_path: BVH file to delete frames from.
    :type file_path: str
    :param start: First frame to be deleted. Frame count starts with 1.
    :type start: int
    :param end: Last frame to be deleted. If None, all frames after start are removed.
    :type end: int
    :param dst_file: If you want to save to a new file, specify its path.
    :type dst_file: str
    :return: Whether the file could be processed and saved.
    :rtype: bool
    
Delete frames in BVH file from start to end or to the end of file.
Delete frames in BVH file from start to end or to the end of file .
def remove_frames(file_path, start, end=None, dst_file=None):
    if end and (start >= end):
        print("First frame to remove is greater than last frame to remove. Aborting.\n"
              "File: {]".format(file_path))
        return False
    file_type = os.path.splitext(file_path)[1].lower()
    if file_type != ".bvh":
        print("ERROR: File extension BVH expected for: {}".format(file_path))
        return False
    try:
        with open(file_path, mode='r') as file_handle:
            lines = file_handle.readlines()
    except FileNotFoundError:
        print("ERROR: file {} not found".format(file_path))
        return False
    frames_idx = lines.index(next(line for line in lines if line.startswith('Frames:')))
    frame1_idx = frames_idx + 2
    if end:
        lines = lines[:start + frame1_idx - 1] + lines[end + frame1_idx:]
    else:
        lines = lines[:start + frame1_idx - 1]
    num_frames = len(lines[frame1_idx:])
    lines[frames_idx] = "Frames: {}\n".format(num_frames)
    if not dst_file:
        dst_file = file_path
    try:
        with open(dst_file, mode='w') as file_handle:
            file_handle.writelines(lines)
    except OSError:
        print("ERROR: Can't write to destination {}".format(dst_file))
        return False
    return True
def remove_frames ( file_path , start , end = None , dst_file = None ) : if end and ( start >= end ) : print ( "First frame to remove is greater than last frame to remove. Aborting.\n" "File: {]" . format ( file_path ) ) return False file_type = os . path . splitext ( file_path ) [ 1 ] . lower ( ) if file_type != ".bvh" : print ( "ERROR: File extension BVH expected for: {}" . format ( file_path ) ) return False try : with open ( file_path , mode = 'r' ) as file_handle : lines = file_handle . readlines ( ) except FileNotFoundError : print ( "ERROR: file {} not found" . format ( file_path ) ) return False frames_idx = lines . index ( next ( line for line in lines if line . startswith ( 'Frames:' ) ) ) frame1_idx = frames_idx + 2 if end : lines = lines [ : start + frame1_idx - 1 ] + lines [ end + frame1_idx : ] else : lines = lines [ : start + frame1_idx - 1 ] num_frames = len ( lines [ frame1_idx : ] ) lines [ frames_idx ] = "Frames: {}\n" . format ( num_frames ) if not dst_file : dst_file = file_path try : with open ( dst_file , mode = 'w' ) as file_handle : file_handle . writelines ( lines ) except OSError : print ( "ERROR: Can't write to destination {}" . format ( dst_file ) ) return False return True
Delete frames in BVH file from start to end or to the end of file.
Delete frames in BVH file from start to end or to the end of file .
"""Delete frames in BVH file from start to end or to the end of file.

    :param file_path: BVH file to delete frames from.
    :type file_path: str
    :param start: First frame to be deleted. Frame count starts with 1.
    :type start: int
    :param end: Last frame to be deleted. If None, all frames after start are removed.
    :type end: int
    :param dst_file: If you want to save to a new file, specify its path.
    :type dst_file: str
    :return: Whether the file could be processed and saved.
    :rtype: bool
    """ # Sanity Check on start and end. # Find first frame. # Slice together the parts we want to keep. # We need to update Frames: # If no destination file is specified, overwrite input file. # If we reached this point, everything went well.
Whether the file could be processed and saved.
Whether the file could be processed and saved .
bool
file_path
BVH file to delete frames from.
BVH file to delete frames from .
start
First frame to be deleted. Frame count starts with 1.
First frame to be deleted . Frame count starts with 1 .
end
Last frame to be deleted. If None, all frames after start are removed.
Last frame to be deleted . If None all frames after start are removed .
dst_file
If you want to save to a new file, specify its path.
If you want to save to a new file specify its path .