免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3344 | 回复: 0
打印 上一主题 下一主题

Open Project Folder (python in maya) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-14 14:34 |只看该作者 |倒序浏览
转:schi

Open Project Folder (python in maya)



在realflow里有个Open Project Folder ...命令用来打开工程项目的目录窗口,我在使用maya的时候我也经常打开maya的工程项目,为什么不把这个简单的功能移植过来呢?
so let's do it.
我google了一下,发现在python中有几种方法来打开指定路径的文件夹
1.使用os.system方法
Python代码
  1. import os   
  2. os.system('explorer "c:\myMayaProject"')  
复制代码
这时会弹出一个cmd.exe窗口来执行我们的命令,然后我们的窗口在所有的窗口的最前面
2.使用os.startfile方法
Python代码
  1. import os   
  2. os.startfile('explorer "c:\myMayaProject"')  
复制代码
不会弹出一个cmd.exe窗口,然后我们的窗口在其它的窗口的后面
3.使用subprocess.Popen方法
Python代码
  1. import subprocess   
  2. subprocess.Popen('explorer "c:\myMayaProject"')  
复制代码
不会弹出一个cmd.exe窗口,然后我们的窗口在所有的窗口的最前面
要用哪个方法就看需要了,这里使用第三个
Python代码
  1. def openProjectFolder():   
  2.     import os, subprocess   
  3.     import sys   
  4.       
  5.     # get project folder's path   
  6.     # 获取工程项目的路径   
  7.     sceneFile = mc.workspace( q=1, dir=1)   
  8.     if not os.path.exists(sceneFile):   
  9.         sys.stderr.write( "No path to open a folder.\n" )   
  10.         raise  
  11.            
  12.     sceneFile = os.path.normcase(sceneFile)   
  13.     subprocess.Popen('explorer "%s"' % sceneFile)  
复制代码
我个人比较喜欢先开场景的目录窗口,所以我用的是
Python代码
  1. def openSceneFolder():   
  2.     import os, subprocess   
  3.     import sys   
  4.       
  5.     # get Scene file folder's path   
  6.     # 获取当前场景的路径   
  7.     sceneFile = os.path.dirname(mc.file( q=1, sn=1 ))   
  8.     if not sceneFile:    # 如果不存在当前场景的路径   
  9.         # get project folder's path   
  10.         # 获取工程项目的路径   
  11.         sceneFile = mc.workspace( q=1, dir=1)   
  12.         if not os.path.exists(sceneFile):   
  13.             sys.stderr.write( "No path to open a folder.\n" )   
  14.             raise  
  15.            
  16.     sceneFile = os.path.normcase(sceneFile)   
  17.     subprocess.Popen('explorer "%s"' % sceneFile)  
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP