Multiverse — Python Scripting Guide

Cookbook

Load a single Alembic file via the Python API:
import mvCompoundShape as mvcs

shapes = mvcs.Open('/tmp/Car.abc')

Load multiple Alembic files for layering via the Python API:
import mvCompoundShape as mvcs

shapes = mvcs.Open('/tmp/Car.abc|/tmp/Road.abc')

Load a sequence.
import mvCompoundShape as mvcs

# We have a sequence contains the files as Ocean_0001.abc Ocean_0002.abc.
shapes = mvcs.Open('/tmp/Ocean_#.abc')

Get the resolved final asset path for a sequence. This is critical for the sequence with play control, the resolved frame time would be used to pick the proper file from the sequence.
import maya.cmds as cmds
import mvCompoundShape as mvcs

shapes = mvcs.Open('/tmp/Ocean_#.abc')
shape = shapes[0]
print cmds.getAttr('%s.OutputAssetPath' % shape)

Query the hierarchal data from the root “/”
import collections
import json
import maya.mel as mel

# The full path to the asset.
assetPath = '/tmp/Car.abc'

# Open the asset.
mel.eval('mvAssetRead -openAsset -assetPath "%s"' % assetPath)

# Load the asset, so we have the all information.
mel.eval('mvAssetRead -loadAsset -assetPath "%s"' % assetPath)

# Return the JSON string which represents the hierarchical data.
treeData = mel.eval('mvAssetRead -hierarchy -recursive -assetPath "%s" -objectPath "/"' % assetPath)

# Convert the text to the JSON object.
tree = json.loads(treeData, object_pairs_hook = collections.OrderedDict)

List the all opened asset
import maya.mel as mel

# Return an string array and each element contains the asset path.