六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 38|回复: 0

Open Project Folder (python in maya)

[复制链接]

升级  28.67%

27

主题

27

主题

27

主题

秀才

Rank: 2

积分
93
 楼主| 发表于 2013-1-15 02:12:59 | 显示全部楼层 |阅读模式
在realflow里有个Open Project Folder ...命令用来打开工程项目的目录窗口,我在使用maya的时候我也经常打开maya的工程项目,为什么不把这个简单的功能移植过来呢?
so let's do it.
我google了一下,发现在python中有几种方法来打开指定路径的文件夹
1.使用os.system方法
import osos.system('explorer "c:\myMayaProject"')
这时会弹出一个cmd.exe窗口来执行我们的命令,然后我们的窗口在所有的窗口的最前面
2.使用os.startfile方法
import osos.startfile('explorer "c:\myMayaProject"')
不会弹出一个cmd.exe窗口,然后我们的窗口在其它的窗口的后面
3.使用subprocess.Popen方法
import subprocesssubprocess.Popen('explorer "c:\myMayaProject"')
不会弹出一个cmd.exe窗口,然后我们的窗口在所有的窗口的最前面
要用哪个方法就看需要了,这里使用第三个
def openProjectFolder():    import os, subprocess    import sys        # get project folder's path    # 获取工程项目的路径    sceneFile = mc.workspace( q=1, dir=1)    if not os.path.exists(sceneFile):        sys.stderr.write( "No path to open a folder.\n" )        raise            sceneFile = os.path.normcase(sceneFile)    subprocess.Popen('explorer "%s"' % sceneFile)
我个人比较喜欢先开场景的目录窗口,所以我用的是
def openSceneFolder():    import os, subprocess    import sys        # get Scene file folder's path    # 获取当前场景的路径    sceneFile = os.path.dirname(mc.file( q=1, sn=1 ))    if not sceneFile:    # 如果不存在当前场景的路径        # get project folder's path        # 获取工程项目的路径        sceneFile = mc.workspace( q=1, dir=1)        if not os.path.exists(sceneFile):            sys.stderr.write( "No path to open a folder.\n" )            raise            sceneFile = os.path.normcase(sceneFile)    subprocess.Popen('explorer "%s"' % sceneFile)
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表