Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 217
Gnn Avatar asked Sep 02 '25 17:09

Gnn


1 Answers

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)
like image 94
Andy Jazz Avatar answered Sep 04 '25 07:09

Andy Jazz