Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
Last active August 29, 2015 13:57
Show Gist options
  • Save fredrikaverpil/9761987 to your computer and use it in GitHub Desktop.
Save fredrikaverpil/9761987 to your computer and use it in GitHub Desktop.
Get Maya environment info #maya
# Get Maya scene filepath and name
sceneFilepath = cmds.file(q=True, sn=True)
sceneName = os.path.basename( sceneFilepath )
sceneNameNoExtension = os.path.splitext(sceneName)[0]
sceneNameExtensionOnly = os.path.splitext(sceneName)[1]
# Get Maya project
mayaProject = cmds.workspace(q=True, rd=True)
# internalVar returns internal variables on a user level, more info: http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/internalVar.html
myScriptDir = cmds.internalVar(userScriptDir=True)
# Traverse backwards from Maya scene file
scenesPath = os.path.dirname( sceneFilepath )
mayaPath = os.path.dirname( scenesPath )
# Check for unsaved changes
fileCheckState = mc.file(q=True, modified=True)
if fileCheckState:
cmds.SaveScene() # Native scene save dialog
else:
print 'No unsaved changes, proceed.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment