Maya 2.0 API


#1

Hi,

I just started with the maya api.

Most learning sources I found are written in 1.0 API which is in general fine as so far I always managed to find a way to write the same thing in 2.0 API.

But now I’m really struggling with the following line

1.0 API

up = om1.MGlobal.upAxis()

which returns a vector

if I do the same thing in the 2.0 API

up = om2.MGlobal.upAxis()

I get this error: ‘OpenMaya.MGlobal’ has no attribute ‘upAxis’

Does anyone know what I’m doing wrong here?

Thanks!


#2

Not all modules which are supported in API 1.0 are already supported in API 2.0.
You can see what’s supported in the developer help under Maya Python API -> Maya Python API 2.0.

e.g. there are only very few methods from MGlobal which are available in API 2.0.


#3

Oki, then I rather stay with the 1.0 API for now I guess.

Thanks a lot for your quick help!


#4

We can guess from context, but you should specify which “API” you’re talking about. Maya has lots of APIs: native C++, MEL, Python’s MEL wrapper (“cmds”), OpenMaya 1 (Python), OpenMaya 2 (Python) and PyMel (a wrapper around cmds, mostly). It’s a complete mess.

Note that there are not just APIs that are only in OM1 that aren’t in OM2, there are APIs in OM2 that aren’t in OM1, so you end up having to use both and sometimes have to jump back and forth (carefully, since the nodes aren’t compatible). They should never have added a second competing Python API unless they were committed to making it the primary one that completely replaces the old one. Instead, it just made the mess worse.


#5

Don’t, OM1 is horrible. OM2 isn’t as complete in terms of 1:1 implementation of the C++ API but it’s of vastly superior quality, and most if not all gaps at this point can be covered with some ingenuity.

In this specific case you can just form your own vector in OM2 after querying upAxis or isYAxisUp/isZAxisUp.
E.G.


upAxis = om2.MVector( 0.0, [0.0, 1.0][om1.MGlobal.isYAxisUp], [0.0, 1.0][om1.MGlobal.isZAxisUp])

or more simply if less concisely


upAxis = om2.MVector(0.0, 1.0, 0.0)
if om1.MGlobal.isZAxisUp:
	upAxis.y = 0.0
	upAxis.z = 1.0


#6

Hmmm, if you are mixing both API’s why not do:

up = om1.MGlobal.upAxis()
om2.Vector(up.x, up.y, up.z)

#7

Sure, no reason not to, it’s that gap bridging stuff you normally write once and stash in a module somewhere for the rest of eternity (which is about the length of time it takes AD to extend OM2 :slight_smile: ).

Provided om1.MVector isn’t one of those stupid swigs that requires you first form and then set the object instead of being able to catch a return into, which is why by default when I wrap something I tend to take other routes.