Example #1
0
def set_project(kwargs):
    node = kwargs['node']
    project_name = node.evalParm('proj')
    # project_name = kwargs['script_value']

    node.parm('scene').set('')
    unset_all_scene_vars()

    data = read_json()

    if project_name == '-':
        hou.unsetenv('PROJECT')
        hou.unsetenv('CODE')
        hou.unsetenv('PROJ_FPS')
        hou.setFps(24)
        hou.unsetenv('PROJECT_PATH')
        hou.unsetenv('SCENES_PATH')
        hou.unsetenv('HDA_PATH')
        hou.unsetenv('SCRIPTS_PATH')
        node.cook(True)
        return

    try:
        project_data = data[project_name]
    except KeyError:
        util.error('Project Data not found')
        return

    hou.putenv('PROJECT', project_name)

    hou.putenv('CODE', project_data['CODE'])

    fps = project_data['FPS']
    hou.putenv('PROJ_FPS', str(fps))
    hou.setFps(fps)

    project_path = project_data['PATH']
    hou.putenv('PROJECT_PATH', project_data['PATH'])

    create_folder_and_var('SCENES_PATH', util.fix_path(os.path.join(project_path, 'scenes')))

    hda_path = util.fix_path(os.path.join(project_path, 'hda'))
    create_folder_and_var('HDA_PATH', hda_path)

    scripts_path = util.fix_path(os.path.join(project_path, 'scripts'))
    create_folder_and_var('SCRIPTS_PATH', scripts_path)

    hda_paths = [hda_path, ]
    scan_path = hou.getenv('HOUDINI_OTLSCAN_PATH')
    if scan_path:
        hda_paths += scan_path.split(';')
    hda_paths = list(set(hda_paths))
    hou.putenv('HOUDINI_OTLSCAN_PATH', ';'.join(hda_paths))
    hou.hda.reloadAllFiles()

    sys.path.append(scripts_path)

    node.cook(True)
Example #2
0
def cache_dir():
    root = hou.getenv('OUTPUT_PATH')
    if not root:
        root = hou.getenv('HIP')
        root = os.path.join(root, 'Output')
    root = util.fix_path(root)

    sub_folders = ['cache']
    path = util.fix_path(os.sep.join(root.split('/') + sub_folders))

    return path
Example #3
0
def cache_path(mode='path'):
    node = hou.pwd()

    name = node.evalParm('cache_name')

    if node.evalParm('enable_version'):
        ver = '_v{0:0>3}'.format(node.evalParm('version'))
    else:
        ver = ''

    if node.evalParm('trange') > 0:
        frame = '.{0:0>4}'.format(int(hou.frame()))
    else:
        frame = ''

    ext = node.evalParm('ext')

    full_name = '{name}{ver}{frame}{ext}'.format(name=name,
                                                 ver=ver,
                                                 frame=frame,
                                                 ext=ext)

    path = util.fix_path(os.path.join(node.evalParm('cache_dir'), full_name))

    if mode == 'path':
        return path
    elif mode == 'name':
        return full_name
    else:
        return
Example #4
0
def scene_menu(kwargs):
    menu = []
    scenes_path = hou.getenv('SCENES_PATH')
    if scenes_path and os.access(scenes_path, os.F_OK):
        for f in os.listdir(scenes_path):
            if os.path.isdir(util.fix_path(os.path.join(scenes_path, f))):
                menu.append(f)
                menu.append(f)
    return menu
Example #5
0
def create_folder_and_var(var, path):
    path = util.fix_path(path)
    hou.putenv(var, path)

    if not os.access(path, os.F_OK):
        os.makedirs(path)
        print('Creating variable {0} and folder [{1}]'.format(var, path))

    return
Example #6
0
def set_scene(kwargs):
    node = kwargs['node']
    scene_name = node.evalParm('scene')

    # If null scene > unset all
    if scene_name == '':
        unset_all_scene_vars()
        node.cook(True)
        return


    # If no PROJECT_PATH var
    project_path = hou.getenv('PROJECT_PATH')
    if not project_path or not os.access(project_path, os.F_OK):
        util.error('Project path is invalid')
        return

    # If no SCENES_PATH var
    scenes_path = hou.getenv('SCENES_PATH')
    if not scenes_path or not os.access(scenes_path, os.F_OK):
        util.error('Scenes path is invalid')
        return

    # If SCENES_PATH var but no folder
    if not os.access(scenes_path, os.F_OK):
        os.makedirs(scenes_path)

    scene_path = util.fix_path(os.path.join(scenes_path, scene_name))
    if not os.access(scene_path, os.F_OK):
        message = 'Scene folder "{0}" does not exist\n'\
                  'Create this folder now?'.format(scene_name)
        choice = hou.ui.displayMessage(message, severity=hou.severityType.ImportantMessage, buttons=('Yes', 'No'))
        if choice == 0:
            os.makedirs(scene_path)
        else:
            unset_all_scene_vars()
            node.cook(True)
            return

    hou.putenv('SCENE', scene_name)
    hou.putenv('SCENE_PATH', scene_path)

    create_folder_and_var('SAVE_PATH', os.path.join(scene_path, 'working_files'))

    output_path = os.path.join(scene_path, 'output')
    create_folder_and_var('OUTPUT_PATH', output_path)
    create_folder_and_var('CACHE_PATH', os.path.join(output_path, 'cache'))
    create_folder_and_var('RENDER_PATH', os.path.join(output_path, 'render'))

    node.cook(True)
Example #7
0
def save_backup_hip(node):
    def generateReport(success, **kwargs):
        parent.parm('hipfile_path').set('None')
        parent.parm('hipfile_date').set('None')
        parent.parm('hipfile_error').set('None')
        parent.parm('hipfile_project').set('None')
        parent.parm('hipfile_source').set('None')

        if success:
            util.print_report('Scene Backup Report', 'Status: Successful',
                              'Scene File: {0}'.format(kwargs['scenefile']),
                              'Date Created: {0}'.format(kwargs['date']))
            parent.parm('hipfile_path').set(kwargs['scenefile'])
            parent.parm('hipfile_date').set(kwargs['date'])
            parent.parm('hipfile_project').set(hou.getenv('PROJECT'))
            parent.parm('hipfile_source').set(hou.hipFile.basename())

        else:
            util.print_report('Scene Backup Report', 'Status Failed',
                              'Error Log: {0}'.format(kwargs['error']))
            parent.parm('hipfile_error').set(kwargs['error'])

    def error_report(message, severity=hou.severityType.Error):
        util.error(message, severity=severity)
        generateReport(False, error=message)

    ### Notes ###
    # file = name of file
    # dir = path to folder
    # path = dir/file

    parent = node.parent()

    backup_dir = hou.getenv('HOUDINI_BACKUP_DIR')
    if not backup_dir:
        hip = hou.getenv('HIP')
        backup_dir = util.fix_path(os.path.join(hip, 'backup'))
        # hou.putenv('HOUDINI_BACKUP_DIR', backup_dir)

    if not os.access(backup_dir, os.F_OK):
        try:
            os.makedirs(backup_dir)
        except:
            error_report('Unable to create backup directory')
            return

    old_files = os.listdir(backup_dir)
    hou.hipFile.save()
    hou.hipFile.saveAsBackup()
    new_files = os.listdir(backup_dir)

    # delta = []
    # for f in new_files:
    #     if f not in old_files:
    #         delta.append(f)

    delta = [f for f in new_files if f not in old_files]

    if len(delta) > 1:
        error_report('Unable to link backup file')
        return

    new_backup_file = delta[0]
    if not new_backup_file:
        error_report('Unable to link backup file')
        return

    new_backup_path = util.fix_path(os.path.join(backup_dir, new_backup_file))

    cache_path = node.evalParm('sopoutput')
    _split = os.path.split(cache_path)
    cache_dir = util.fix_path(_split[0])
    cache_file = _split[1]
    cache_name = cache_file.split('.')[0]

    cache_hip_dir = os.path.join(cache_dir, 'cache_hips')

    if not os.access(cache_hip_dir, os.F_OK):
        try:
            os.makedirs(cache_hip_dir)
        except:
            error_report('Unable to create a directory for cache .hip files')
            return

    cache_hip_file = '{name}{ext}'.format(
        name=cache_name, ext=os.path.splitext(new_backup_file)[-1])
    cache_hip_path = util.fix_path(os.path.join(cache_hip_dir, cache_hip_file))

    try:
        shutil.copy(new_backup_path, cache_hip_path)
    except:
        error_report('Unable to copy backup file to cache .hip file directory')
        return

    date = datetime.datetime.now()
    generateReport(True, scenefile=cache_hip_path, date=str(date))
Example #8
0
def add_proj():
    data = read_json()
    # Init
    _proj_name = None
    path = None
    path_name = None
    path_code = None
    path_fps = None
    # Select Proejct Path
    repeat = True
    while repeat:
        repeat = False
        _path = hou.ui.selectFile(title='Select Project Directory',
                                  file_type=hou.fileType.Directory)
        path = os.path.dirname(_path)

        if path == '':
            return

        for k, v in data.items():
            if util.fix_path(path) == util.fix_path(v['PATH']):
                util.error(
                    'Project path is already used by another project {0}\nPlease select a different path'
                    .format(k))
                repeat = True
                break
        if repeat:
            continue

        _proj_name = os.path.split(path)[-1]

    # Select Project Name, Code and FPS
    repeat = True
    while repeat:
        repeat = False
        inputs = hou.ui.readMultiInput(message='Enter Project Data',
                                       input_labels=('Project Name',
                                                     'Project Code', 'FPS'),
                                       buttons=('OK', 'Cancel'),
                                       initial_contents=(_proj_name, '', '24'))

        if inputs[0] == 1:
            return

        proj_name = inputs[1][0]
        proj_code = inputs[1][1]
        proj_fps = inputs[1][2]

        if proj_name == '' or proj_code == '' or proj_fps == '':
            util.error('Please fill in all fields')
            repeat = True
            continue

        try:
            proj_fps = int(proj_fps)
        except ValueError:
            util.error(
                'FPS not set to a number. \n Please enter a whole number')
            repeat = True
            continue

        for k, v in data.items():
            if proj_name == k:
                util.error(
                    'Project name is already in use\nPlease select a different name'
                )
                repeat = True
                break

            if proj_code == v['CODE']:
                util.error(
                    'Project code is already in use\nPlease select a different code'
                )
                repeat = True
                break

        if repeat:
            continue

    if proj_name and proj_code and proj_fps:
        proj_data = {'CODE': proj_code, 'PATH': path, 'FPS': proj_fps}
        data[proj_name] = proj_data

    if data:
        with open(proj_list, 'w') as f:
            json.dump(data, f, sort_keys=True, indent=4)