Esempio n. 1
0
def inplace_checkin(virtual_snapshot,
                    repo_name,
                    update_versionless,
                    only_versionless=False,
                    generate_icons=True,
                    selected_objects=False,
                    ext_type='mayaAscii',
                    setting_workspace=False):

    main_version = 'versioned'
    if only_versionless:
        main_version = 'versionless'

    scene_name = virtual_snapshot[0][1][main_version]['names'][0]
    scene_path = gf.form_path(repo_name['value'][0] + '/' +
                              virtual_snapshot[0][1][main_version]['paths'][0])
    playblast_name = virtual_snapshot[1][1][main_version]['names'][0]
    playblast_path = gf.form_path(
        repo_name['value'][0] + '/' +
        virtual_snapshot[1][1][main_version]['paths'][0])

    full_scene_path = scene_path + '/' + ''.join(scene_name)
    full_playblast_path = playblast_path + '/' + ''.join(playblast_name)
    # create dest dirs
    if not os.path.exists(scene_path):
        os.makedirs(scene_path)
    if not os.path.exists(playblast_path):
        os.makedirs(playblast_path)
    # saving maya scene
    try:
        if ext_type in ['mayaAscii', 'mayaBinary']:
            cmds.file(rename=full_scene_path)
        renamed = True
    except:
        renamed = False
    try:
        if selected_objects:
            if ext_type in ['mayaAscii', 'mayaBinary']:
                cmds.file(exportSelected=selected_objects,
                          type=ext_type,
                          pr=True,
                          eur=True)
            else:
                cmds.file(full_scene_path,
                          exportSelected=selected_objects,
                          type=ext_type,
                          pr=True,
                          eur=True)
        else:
            cmds.file(save=True, type=ext_type)
        saved = True
    except:
        saved = False

    # check_ok = True

    files_objects_list = []

    if renamed and saved:
        if setting_workspace:
            pass
            # set_workspace(dest_scene_ver, all_process)

        # isolate selected to create proper playblast
        current_panel = cmds.paneLayout('viewPanes', q=True, pane1=True)
        if selected_objects:
            cmds.isolateSelect(current_panel, state=True)
            mel.eval('enableIsolateSelect {0} 1;'.format(current_panel))

        current_frame = cmds.currentTime(query=True)

        cmds.playblast(forceOverwrite=True,
                       format='image',
                       completeFilename=full_playblast_path,
                       showOrnaments=False,
                       widthHeight=[960, 540],
                       sequenceTime=False,
                       frame=[current_frame],
                       compression='jpg',
                       offScreen=False,
                       viewer=False,
                       percent=100)

        if selected_objects:
            cmds.isolateSelect(current_panel, state=False)
            mel.eval('enableIsolateSelect {0} 0;'.format(current_panel))

        match_template = gf.MatchTemplate(['$FILENAME.$EXT'])

        files_objects_dict = match_template.get_files_objects(
            [full_scene_path, full_playblast_path], sort=False)
        maya_app_info_dict = get_maya_info_dict()

        for fl in files_objects_dict.get('file'):
            fl.set_app_info(maya_app_info_dict)
            files_objects_list.append(fl)
        file_paths = [[full_scene_path], [full_playblast_path]]

        check_ok = tc.inplace_checkin(
            file_paths,
            virtual_snapshot,
            repo_name,
            update_versionless,
            only_versionless,
            generate_icons,
            files_objects_list,
        )
    else:
        check_ok = False

    maya.utils.processIdleEvents()

    return check_ok, files_objects_list
Esempio n. 2
0
def new_save_scene(search_key, context, description, snapshot_type='file', all_process=None, repo=None, update_versionless=True, file_types='maya', postfixes=None, version=None, ext_type=None, is_current=False, is_revision=False, mode=None, create_playblast=True, selected_objects=False):

    types = {
        'mayaBinary': 'mb',
        'mayaAscii': 'ma',
    }

    setting_workspace = False

    exts = [types[ext_type]]
    file_types = [file_types]
    file_names = ['']
    postfixes = ['']
    subfolders = ['']

    print exts, 'exts'
    print file_types, ''
    print file_names, ''
    print postfixes, ''
    print subfolders, ''

    if create_playblast:
        exts.extend(['jpg', 'jpg', 'png'])
        file_types.extend(['playblast', 'web', 'icon'])
        file_names.extend(['', '', ''])
        postfixes.extend(['playblast', '', ''])
        subfolders.extend(['__preview', '__preview', '__preview'])

    # ask user to confirm saving
    virtual_snapshot = tc.checkin_virtual_snapshot(
        search_key,
        context,
        snapshot_type=snapshot_type,
        ext=exts,
        file_type=file_types,
        file_name=file_names,
        file_postfix=postfixes,
        subfolders=subfolders,
        is_revision=is_revision,
        repo=repo,
        update_versionless=update_versionless,
        keep_file_name=False,
        version=version,
    )

    if virtual_snapshot:
        # save maya scene to destined folder
        dest_path_ver = gf.form_path(repo['value'][0] + '/' + virtual_snapshot['versioned']['paths'][0])
        dest_scene_ver = dest_path_ver + '/' + virtual_snapshot['versioned']['names'][0]

        dest_path_playblast_ver = gf.form_path(repo['value'][0] + '/' + virtual_snapshot['versioned']['paths'][1])
        dest_playblast_ver = dest_path_playblast_ver + '/' + virtual_snapshot['versioned']['names'][1]
        dest_web_ver = dest_path_playblast_ver + '/' + virtual_snapshot['versioned']['names'][2]
        dest_icon_ver = dest_path_playblast_ver + '/' + virtual_snapshot['versioned']['names'][3]

        # create dest dirs
        if not os.path.exists(dest_path_ver):
            os.makedirs(dest_path_ver)
        if not os.path.exists(dest_path_playblast_ver):
            os.makedirs(dest_path_playblast_ver)

        # add info about particular scene
        skey_link = 'skey://{0}&context={1}'.format(search_key, context)
        if not cmds.attributeQuery('tacticHandler_skey', node='defaultObjectSet', exists=True):
            cmds.addAttr('defaultObjectSet', longName='tacticHandler_skey', dataType='string')
        cmds.setAttr('defaultObjectSet.tacticHandler_skey', skey_link, type='string')

        # saving maya scene
        try:
            cmds.file(rename=dest_scene_ver)
            renamed = True
        except:
            renamed = False
        try:
            cmds.file(save=True, type=ext_type)
            saved = True
        except:
            saved = False

        progres_bar = env_inst.ui_check_tree['checkin'][search_key.split('?')[0]].progres_bar
        check_ok = True

        if renamed and saved:
            if setting_workspace:
                set_workspace(dest_scene_ver, all_process)

            current_frame = cmds.currentTime(query=True)
            cmds.playblast(
                forceOverwrite=True,
                format='image',
                completeFilename=dest_playblast_ver,
                showOrnaments=False,
                widthHeight=[960, 540],
                sequenceTime=False,
                frame=[current_frame],
                compression='jpg',
                offScreen=True,
                viewer=False,
                percent=100
            )

            mode = 'inplace'

            tc.generate_web_and_icon(dest_playblast_ver, dest_web_ver, dest_icon_ver)

            file_paths = [dest_scene_ver, dest_playblast_ver, dest_web_ver, dest_icon_ver]

            check_ok = tc.inplace_checkin(
                file_paths,
                progres_bar,
                virtual_snapshot,
                repo,
                update_versionless,
                check_ok
            )

            if check_ok:
                relative_paths = []
                file_sizes = []
                for fp in file_paths:
                    file_sizes.append(gf.get_st_size(fp))

                tc.checkin_snapshot(
                    search_key,
                    context,
                    snapshot_type=snapshot_type,
                    is_revision=is_revision,
                    description=description,
                    version=version,
                    update_versionless=update_versionless,
                    file_types=file_types,
                    file_names=file_names,
                    file_paths=file_paths,
                    relative_paths=relative_paths,
                    file_sizes=file_sizes,
                    exts=exts,
                    keep_file_name=False,
                    repo_name=repo['value'][3],
                    virtual_snapshot=virtual_snapshot,
                    mode=mode,
                    create_icon=False
                )
            progres_bar.setValue(100)

        progres_bar.setVisible(False)

        if check_ok:
            return True
        else:
            return False
    else:
        return False