Using UsdView with Maya

UsdView is a part of the USD toolset created by Pixar which combines interactive GL preview, navigation & introspection, a (growing) set of diagnostic or debugging facilities and an interactive python interpreter.

You can access UsdView with an installation of the MayaUSD plug-in and Maya 2022. It can be accessed in two ways:

  1. Run UsdView from within Maya 2022
  2. Run UsdView from the command line

1. To run UsdView from within Maya 2022

USDView needs an asset to view, hence, you need to select a USD asset in Maya before running this script.

Run the following python script from the Script Editor:

import maya.cmds as cmds
import ufe
from pxr import Usd
import mayaUsd as uLib
import os
import sys
import subprocess
if ufe.GlobalSelection.get().empty():
    cmds.error('Select any ufe item under (and including) gateway node')
ufeItem = ufe.GlobalSelection.get().back()
ufePathGateway = ufe.Path(ufeItem.path().segments[0])
stage = uLib.ufe.getStage(str(ufePathGateway))
sdfLayer = stage.GetRootLayer()
mayaVer = int(cmds.about(q=True, majorVersion=True))
if mayaVer == 2022:
    mayapy = os.path.join(os.environ['MAYA_LOCATION'], 'bin', 'mayapy{ver}'.format(ver='' if sys.version_info.major == 3 else '2'))
else:
    mayapy = os.path.join(os.environ['MAYA_LOCATION'], 'bin', 'mayapy')
usdViewPath = os.path.join(os.environ['USD_LOCATION'], 'bin', 'usdview')
# Install OpenGL module, if needed
try:
    import OpenGL
except:
    subprocess.check_call([mayapy, '-m', 'pip', 'install', 'PyOpenGL==3.1.0'])
CREATE_NO_WINDOW = 0x08000000
subprocess.Popen([mayapy, usdViewPath, sdfLayer.realPath], creationflags=CREATE_NO_WINDOW)
Important: For the final line of the example launching subprocess, linux users should remove the creationflags=CREATE_NO_WINDOW parameter. It is a windows-only parameter.
Tip: For quick access, you can also add UsdView to a shelf button in Maya by selecting and dragging the text to the shelf.

2. To run UsdView from the Command Line

Important: The following instructions are specific to using the Windows operating system. For other OS platforms (ie. Mac and Linux) paths must be adjusted accordingly.
Note: The version of MayaUSD shipped with Maya 2022 was built using python from Maya and mayapy, so UsdView will run with mayapy.To run with Python 2, use mayapy2 (instead of "mayapy") and change to USD2 (from “USD3”).

Open a command prompt and run the following commands, replacing the <version> tags with your appropriate version:

set PATH=C:\Program Files\Autodesk\Maya<VersionNumber>\bin;C:\Program Files\Autodesk\MayaUSD\Maya<VersionNumber>\<plugin-version>\mayausd\USD3\bin;C:\Program Files\Autodesk\MayaUSD\Maya<VersionNumber>\<plugin-version>\mayausd\USD3\lib;%PATH%
mayapy -m pip install PyOpenGL==3.1.0
mayapy C:\Program Files\Autodesk\MayaUSD\Maya<VersionNumber>\<plugin-version>\mayausd\USD3\bin\usdview <your_file>

Compatibility Note: UsdView is accessible for Maya 2020. However, Maya 2020 exclusively supports python2. The aforementioned scripts would have to be adjusted accordingly for py2 and replace "USD3" with just "USD" for use with Maya 2020.