4

I'm trying to open a maya scene .ma at the end of a Python script,

the path looks like that: G:\ProjectPath\Scene.ma.

But the only command I know for this is MEL command:

file -f -options "v=0; p=17; f=0" -ignoreVersion -typ "mayaAscii" -o 
"G:/ProjectPath/Scene.ma"; 
addRecentFile("G:/ProjectPath/Scene.ma", "mayaAscii");

Do someone know the way to do it in Python?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Gnn
  • 107
  • 1
  • 2
  • 7

1 Answers1

5

Here's a quick way you can do it via Python:

import maya.cmds as cmds

# Windows path version
cmds.file('G:/ProjectPath/Scene.ma', o=True)

# Mac path version
cmds.file('/Users/mac/Desktop/Scene.ma', o=True)

Or try this version if you get messages like this # Error: Unsaved changes:

file_path = 'G:/ProjectPath/Scene.ma' 
cmds.file(new=True, force=True) 
cmds.file(file_path, open=True)
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • hello Andy..thanks for your answer, i'd try this for windows: cmds.file( 'G:/ProjectPath/Scene.ma', o = True ) maya just given me this answer: # Error: Unsaved changes. # Traceback (most recent call last): # File "", line 3, in # RuntimeError: Unsaved changes. # as i'm on a new scene, i'm not understand what appened... – Gnn Apr 16 '17 at 18:46
  • it's just the exact path to the scene: import maya.cmds as cmds cmds.file( 'G:/ProjectPath/241/000A/001/LGT/SB_241_000A_001_LGT_005.ma', o = True ) – Gnn Apr 16 '17 at 19:15
  • Try to flush the opened new scene first: import maya.cmds as cmds file_path = 'G:/ProjectPath/Scene.ma' cmds.file( new=True, force=True ) cmds.file( file_path, open=True ) – Andy Jazz Apr 16 '17 at 19:27
  • 1
    thank you very muxh Andy, i'll never find that without your help :) – Gnn Apr 16 '17 at 19:39
  • Can I somehow use this without forcing a new scene with 'cmds.file(new=True, force=True)', so that the user get asked whether he wants to save his current open file or not? – Lala_Ghost Sep 17 '20 at 08:12