World Space Quaternions

Hi, I’m a bit stumped trying to get some world space quaternions with OpenMaya.

I’m getting local space ones with:
(OpenMaya.MFnTransform object).rotation(asQuaternion=True)

I thought It’d be able to get world space ones with:
(OpenMaya.MFnTransform object).rotation(OpenMaya.MSpace.kWorld, asQuaternion=True)

but I get an “(kInvalidParameter): Object is incompatible with this method” error.

Am I doing something wrong? Or if someone has an alternative method I’m happy to hear it :slight_smile:

It might be that you are required to initialize the MFnTransform with a MDagPath instead of MObject. Could that be the case?

Just gave this a quick go - that’s indeed the case.

This works :green_circle:

from maya import cmds
import maya.api.OpenMaya as om

# Transform
transform = cmds.createNode("transform")

sel = om.MSelectionList()

# Use MDagPath to make it work
dag = sel.getDagPath(0)
fn = om.MFnTransform(dag)
fn.rotation(om.MSpace.kWorld, asQuaternion=True)

This doesn’t work :red_circle:

obj = sel.getDependNode(0)
fn = om.MFnTransform(obj)
fn.rotation(om.MSpace.kWorld, asQuaternion=True)
# RuntimeError: (kInvalidParameter): Object is incompatible with this method # 

Note the use of an MDagPath does work but an MObject does not.


Ah brilliant, thanks a lot :smiley: