Python maya.cmds.workspace() Examples

The following are 9 code examples for showing how to use maya.cmds.workspace(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module maya.cmds , or try the search function .

Example 1
Project: core   Author: getavalon   File: pipeline.py    License: MIT License 6 votes vote down vote up
def _set_project():
    """Sets the maya project to the current Session's work directory.

    Returns:
        None

    """
    workdir = api.Session["AVALON_WORKDIR"]

    try:
        os.makedirs(workdir)
    except OSError as e:
        # An already existing working directory is fine.
        if e.errno == errno.EEXIST:
            pass
        else:
            raise

    cmds.workspace(workdir, openWorkspace=True) 
Example 2
Project: core   Author: getavalon   File: pipeline.py    License: MIT License 6 votes vote down vote up
def _on_task_changed(*args):

    _update_menu_task_label()

    workdir = api.Session["AVALON_WORKDIR"]
    if os.path.exists(workdir):
        logger.info("Updating Maya workspace for task change to %s", workdir)

        _set_project()

        # Set Maya fileDialog's start-dir to /scenes
        frule_scene = cmds.workspace(fileRuleEntry="scene")
        cmds.optionVar(stringValue=("browserLocationmayaBinaryscene",
                                    workdir + "/" + frule_scene))

    else:
        logger.warning("Can't set project for new context because "
                       "path does not exist: %s", workdir) 
Example 3
Project: SISideBar   Author: ShikouYamaue   File: setup.py    License: MIT License 6 votes vote down vote up
def check_open():
    current_project = cmds.workspace(q=True, rootDirectory=True)
    scene_path = cmds.file(q=True, sceneName=True)
    scene_name = cmds.file(q=True, shortName=True, sceneName=True)
    msg01 = lang.Lang(
                en='Workspace not found',
                ja=u'ワークスペースがみつかりません')
    dir_list = scene_path.split('/')
    for i in range(len(dir_list)):
        dir_list = dir_list[:-1]
        root_dir = '/'.join(dir_list)+'/'
        try:
            all_files = os.listdir(root_dir)
        except:
            cmds.inViewMessage( amg=msg01.output(), pos='midCenterTop', fade=True, ta=0.75, a=0.5)
            return
        for file in all_files:
            if file == 'workspace.mel':
                set_work_space(root_dir)
                return
    cmds.inViewMessage( amg=msg01.output(), pos='midCenterTop', fade=True, ta=0.75, a=0.5) 
Example 4
Project: pyblish-maya   Author: pyblish   File: collect_workspace.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def process(self, context):
        import os
        from maya import cmds

        workspace = cmds.workspace(rootDirectory=True, query=True)
        if not workspace:
            # Project has not been set. Files will
            # instead end up next to the working file.
            workspace = cmds.workspace(dir=True, query=True)

        # Maya returns forward-slashes by default
        normalised = os.path.normpath(workspace)

        context.set_data('workspaceDir', value=normalised)

        # For backwards compatibility
        context.set_data('workspace_dir', value=normalised) 
Example 5
Project: core   Author: getavalon   File: pipeline.py    License: MIT License 5 votes vote down vote up
def launch_workfiles_app(*args):
    workfiles.show(
        os.path.join(
            cmds.workspace(query=True, rootDirectory=True),
            cmds.workspace(fileRuleEntry="scene")
        ),
        parent=self._parent
    ) 
Example 6
Project: SISideBar   Author: ShikouYamaue   File: setup.py    License: MIT License 5 votes vote down vote up
def set_work_space(root_dir):
    cmds.workspace(root_dir, o=True)
    current_project = cmds.workspace(q=True, rootDirectory=True)
    print 'Set Current Work Space :', current_project
    msg00 = lang.Lang(
                en='Set Current Work Space :<hl>'+current_project+'<hl>',
                ja=u'現在のプロジェクトを<hl>' +current_project+u'</hl>に設定しました')
    cmds.inViewMessage( amg=msg00.output(), pos='midCenterTop', fade=True, ta=0.75, a=0.5)
    
#ドラッグドロップでオープンシーンする 
Example 7
Project: cmt   Author: chadmv   File: shortcuts.py    License: MIT License 5 votes vote down vote up
def _get_file_path(file_filter, key, file_mode):
    """Get a file path from a file dialog.

    :param file_filter: File filter eg "Maya Files (*.ma *.mb)"
    :param key: Optional key value to access the starting directory which is saved in
        the persistent cache.
    :param file_mode: 0 Any file, whether it exists or not.
        1 A single existing file.
        2 The name of a directory. Both directories and files are displayed in the dialog.
        3 The name of a directory. Only directories are displayed in the dialog.
        4 Then names of one or more existing files.
    :return: The selected file path
    """
    start_directory = cmds.workspace(q=True, rd=True)
    if key is not None:
        start_directory = get_setting(key, start_directory)

    file_path = cmds.fileDialog2(
        fileMode=file_mode, startingDirectory=start_directory, fileFilter=file_filter
    )
    if key is not None and file_path:
        file_path = file_path[0]
        directory = (
            file_path if os.path.isdir(file_path) else os.path.dirname(file_path)
        )
        set_setting(key, directory)
    return file_path


# MScriptUtil 
Example 8
Project: maya-capture-gui   Author: Colorbleed   File: lib.py    License: MIT License 5 votes vote down vote up
def get_project_rule(rule):
    """Get the full path of the rule of the project"""

    workspace = cmds.workspace(query=True, rootDirectory=True)
    folder = cmds.workspace(fileRuleEntry=rule)
    if not folder:
        log.warning("File Rule Entry '{}' has no value, please check if the "
                    "rule name is typed correctly".format(rule))

    return os.path.join(workspace, folder) 
Example 9
Project: SISideBar   Author: ShikouYamaue   File: texture.py    License: MIT License 4 votes vote down vote up
def texture_path_2_local_with_copy():
    all_textures = cmds.ls(type='file')
    pj_path = cmds.workspace(q=1, rd=1)
    tx_path = pj_path + "sourceimages/"
    
    copy_textures = []
    un_copy_texture = []
    same_texture = []
    msg = '- Result -'
    for texture in all_textures:
        texName = cmds.getAttr(texture + '.fileTextureName')
        
        splitText = '/'
        #区切り文字が\\の場合の対応
        if not splitText in texName:
            splitText = '\\'
        tempName = texName.split(splitText)
        file_name = tempName[-1]
        #外部ファイルコピー
        if not texName.startswith('sourceimages'):
            if os.path.exists(texName):
                try:
                    local_path = tx_path+file_name
                    shutil.copyfile(texName, local_path)
                    copy_textures.append(file_name)
                except shutil.Error:
                    same_texture.append(file_name)
            else:
                un_copy_texture.append(file_name)
                
        newName = 'sourceimages'+splitText+file_name
        cmds.setAttr (texture + '.fileTextureName', newName, type = 'string')
    if copy_textures:
        msg += '\n*** Copy file to local directory ***'
        for tex in copy_textures:
            msg += '\n'+tex
    if un_copy_texture:
        msg += '\n*** Copy Error / Texture file not found ***'
        for tex in un_copy_texture:
            msg += '\n'+tex
    if same_texture:
        msg += '\n*** Copy Error / Texture already exist in locals ***'
        for tex in same_texture:
            msg += '\n'+tex
    cmds.confirmDialog(m = msg)