コード例 #1
0
def _save_fbx(file_, force=False):
    """Save fbx file.

    Args:
        file_ (str): fbx path
        force (bool): replace without confirmation
    """
    _file = File(get_path(file_))
    _file.delete(wording='Replace', force=force)
    for _mel in [
            'FBXExportUpAxis z',
            'FBXExportFileVersion -v FBX201800',
            'FBXExportSmoothingGroups -v true',
            'FBXExportSmoothMesh -v true',
            'FBXExportTangents -v true',
            'FBXExportSkins -v true',
            'FBXExportShapes -v true',
            'FBXExportEmbeddedTextures -v false',
            'FBXExportApplyConstantKeyReducer -v true',
            'FBXExportSplitAnimationIntoTakes -c',
            'FBXExport -f "{}"'.format(_file.path),
    ]:
        mel.eval(_mel)
    dprint('Wrote file', _file.nice_size(), _file.path)
    assert _file.exists()
コード例 #2
0
def reference_publish(file_, verbose=0):
    """Reference a publish into the current scene.

    Args:
        file_ (str): path to reference
        verbose (int): print process data
    """
    _file = get_path(file_)
    assert isinstance(_file, six.string_types)

    # Find ref util module
    _mgr = find_tank_app('assetmanager')
    _ref_util = find_tank_mod(
        'tk_multi_assetmanager.reference_util', catch=True)
    if not _ref_util:
        _init_tank()
        _ref_util = find_tank_mod('tk_multi_assetmanager.reference_util')
    lprint('REF UTIL', _ref_util, verbose=verbose)

    _ref_list = _mgr.reference_list
    _pub_dir = _ref_list.asset_manager.publish_directory
    _publish = _pub_dir.publish_from_path(_file)
    lprint('PUBLISH', _publish, verbose=verbose)
    if not _publish:
        raise RuntimeError('Failed to build publish '+_file)

    _ref = _ref_util.reference_publish(_publish)
    lprint('REF', _ref, verbose=verbose)
    _ref_list.update()

    return _ref[0]
コード例 #3
0
def open_scene(file_, force=False, prompt=False, lazy=False, load_refs=True):
    """Open the given scene.

    Args:
        file_ (str): file to open
        force (bool): lose unsaved changes without confirmation
        prompt (bool): show missing reference dialogs
        lazy (bool): abandon load if scene is already open
        load_refs (bool): load references
    """
    from psyhive import host

    _file = get_path(file_)
    if lazy and host.cur_scene() == _file:
        return
    if not force:
        host.handle_unsaved_changes()
    if File(_file).extn == 'fbx':
        load_plugin('fbxmaya')

    _kwargs = {}
    if not load_refs:
        _kwargs['loadReferenceDepth'] = 'none'

    cmds.file(_file,
              open=True,
              force=True,
              prompt=prompt,
              ignoreVersion=True,
              **_kwargs)
コード例 #4
0
def render(file_,
           camera=None,
           layer='defaultRenderLayer',
           col_mgt=True,
           force=False,
           verbose=0):
    """Render the current scene.

    Args:
        file_ (str): path to save rendered image
        camera (str): camera to render through
        layer (str): layer to render
        col_mgt (bool): apply colour management
        force (bool): replace existing without confirmation
        verbose (int): print process data
    """
    from maya_psyhive import open_maya as hom
    cmds.loadPlugin('mtoa', quiet=True)
    from mtoa.cmds import arnoldRender

    _cam = camera
    if not _cam:
        _cam = hom.get_active_cam()

    # Prepare output path
    _file = File(get_path(file_))
    _file.test_dir()
    _file.delete(force=force, wording='Replace')

    # Prepare arnold
    cmds.setAttr("defaultArnoldRenderOptions.abortOnError", False)
    cmds.setAttr("defaultArnoldDriver.colorManagement", int(col_mgt))
    cmds.setAttr("defaultArnoldDriver.mergeAOVs", True)
    _extn = {'jpg': 'jpeg'}.get(_file.extn, _file.extn)
    cmds.setAttr('defaultArnoldDriver.aiTranslator', _extn, type='string')
    cmds.setAttr('defaultArnoldDriver.prefix',
                 "{}/{}".format(_file.dir, _file.basename),
                 type='string')
    cmds.setAttr("defaultRenderGlobals.animation", False)

    # Execute renders
    assert not _file.exists()
    arnoldRender.arnoldRender(640, 640, True, True, _cam, ' -layer ' + layer)
    if not _file.exists():
        _tmp_file = File('{}/{}_1.{}'.format(_file.dir, _file.basename,
                                             _file.extn))
        print ' - TMP FILE', _tmp_file.path
        assert _tmp_file.exists()
        _tmp_file.move_to(_file)
    assert _file.exists()
    lprint('RENDERED IMAGE', _file.path, verbose=verbose)
コード例 #5
0
def build(mod, all_defs=True):
    """Build an interface for the given module.

    In maya it will build a MayaPyGui, otherwise it will build a QtPyGui.

    Args:
        mod (module): module to build gui from
        all_defs (bool): build all defs (not just install_gui decorated ones)

    Returns:
        (BasePyGui): interface instance
    """
    _file = get_path(mod).replace('.pyc', '.py')
    if host.NAME == 'maya':
        from .pyg_maya import MayaPyGui as _class
    else:
        from .pyg_qt import QtPyGui as _class
    return _class(_file, all_defs=all_defs)
コード例 #6
0
    def swap_to(self, file_):
        """Swap this reference file path.

        Args:
            file_ (str): new file path
        """
        _file = get_path(file_)
        if not os.path.exists(_file):
            raise OSError("Missing file: {}".format(_file))
        try:
            cmds.file(_file,
                      loadReference=self.ref_node,
                      ignoreVersion=True,
                      options="v=0",
                      force=True)
        except RuntimeError as _exc:
            if _exc.message == 'Maya command error':
                raise RuntimeError('Maya errored on opening file ' + _file)
            raise _exc
コード例 #7
0
def open_scene(file_, func=None, force=False, lazy=False):
    """Open the given scene file.

    A warning is raised if the current scene has been modified.

    Args:
        file_ (str): file to open
        func (fn): override save function
        force (bool): lose current scene with no warning
        lazy (bool): abandon open scene if file is already open
    """
    _file = get_path(file_)
    if lazy and cur_scene() == _file:
        print 'SCENE ALREADY OPEN', _file
        return
    if not force and _scene_modified():
        handle_unsaved_changes()
    _func = func or wrap_fn(_force_open_scene, _file)
    _func()
コード例 #8
0
def save_as(file_, revert_filename=True, force=False, verbose=0):
    """Save the current scene at the given path without changing cur filename.

    Args:
        file_ (str): path to save file to
        revert_filename (bool): disable revert filename
        force (bool): overwrite with no confirmation
        verbose (int): print process data
    """
    _cur_filename = hou.hipFile.name()

    # Test file paths
    _file = File(abs_path(get_path(file_)))
    _file.delete(wording='replace existing', force=force)

    # Execute save
    _file.test_dir()
    hou.hipFile.save(_file.path)
    dprint('SAVED SCENE', _file.nice_size(), _file.path, verbose=verbose)

    if revert_filename:
        hou.hipFile.setName(_cur_filename)