在realflow里有个Open Project Folder ...命令用来打开工程项目的目录窗口,我在使用maya的时候我也经常打开maya的工程项目,为什么不把这个简单的功能移植过来呢?
so let's do it.
我google了一下,发现在python中有几种方法来打开指定路径的文件夹
1.使用os.system方法
import os
os.system('explorer "c:\myMayaProject"')
这时会弹出一个cmd.exe窗口来执行我们的命令,然后我们的窗口在所有的窗口的最前面
2.使用os.startfile方法
import os
os.startfile('explorer "c:\myMayaProject"')
不会弹出一个cmd.exe窗口,然后我们的窗口在其它的窗口的后面
3.使用subprocess.Popen方法
import subprocess
subprocess.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)