OpenMaya Animation Export and Import

I wanted to show case how to write an Animation Import/ Exporter in Python Open Maya 1.0.

To start with, I will be using my own methods to achieve this, specifically, animation_utils.py
What is important to know about OpenMaya 1.0 is that it is closely correlated with C++ types and arguments. In OpenMaya 1.0, I’ve created a ScriptUtil class to get “storage boxes’ that are meant to put into functions to collect information. Here’s an example:

# import modules
from maya import OpenMayaAnim
from maya_utils import object_utils
# let's grab tangent information from a MFnAnimCurve function
plug_node = object_utils.get_plug(object_name, attribute_name)
anim_fn = OpenMaya.MFnAnimCurve(plug_node)
# create a double pointer storage
weight = object_utils.ScriptUtil(as_double_ptr=True)
angle = OpenMaya.MAngle()# grab the key information at indexanim_node_index = 0
# store the information variables, "angle" and "weight.ptr"
anim_fn.getTangent(anim_node_index, angle, weight.ptr, True)
# grab the stored keys' information
radians_angle = angle.asRadians()
weight_dbl = weight.get_double()print("--> ", radians_angle, weight_dbl)
# ____________________________________________
# get_tangent_angle.py

And that’s really all you need to know about OpenMaya information gathering, from functions. Be sure to also check the OpenMaya’s C++ documentation to correlate to what types of information can be available:

https://download.autodesk.com/us/maya/2010help/api/class_m_fn_anim_curve.html#e04c4b8a03e8ccd5976483eecbaf5fb3

from importlib import reload
import sys, os
pipe_path = "C:/Work/pipeline/Maya/Python"
if pipe_path not in sys.path:
    sys.path.append(pipe_path)
from maya_utils import animation_utils as au
from maya_utils import object_utils
from maya_utils import atom_utils
reload(atom_utils)
reload(au)
# Maya ATOM 
atom_utils.export_atom()
atom_utils.import_atom()

# Maya CMD
au.read_anim_data_cmd()
au.write_anim_data_cmd()

# Open Maya
au.read_anim_data()
au.write_anim_data()

I go over explaining how all this works on my Youtube Channel here

Available bouncy-ball animation file and link to my GitHub repository:

Leave a Reply

Your email address will not be published. Required fields are marked *