Open Project Folder (python in maya)

在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)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值