Gnn Gnn - 8 months ago 43
Python Question

Open a .ma file (ASCII) in Maya with Python?

I'm trying to open a maya scene

at the end of a Python script,

the path looks like that:

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

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

Do someone know the way to do it in Python?

Answer Source

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

import maya.cmds as cmds

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

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

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

file_path = 'G:/ProjectPath/' 
cmds.file( new = True, force = True ) 
cmds.file( file_path, open = True )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download