Maya Python API 2.0 - How to create a custom transform node?

Maya Python API 2.0 - How to create a custom transform node?

ilpvfx
Explorer Explorer
5,122 Views
8 Replies
Message 1 of 9

Maya Python API 2.0 - How to create a custom transform node?

ilpvfx
Explorer
Explorer

Hi,

 

After the update to API 2.0, the MFnPlugin.registerTransform method has been removed. The only example of creating a custom transform node using Python still uses API 1.0 in the devkit examples (and the C++ API still uses that method as well, so I can't try to follow their examples either).

 

By guessing, I took the original code and stripped it down to the bare minimum just to try using MFnPlugin.registerNode with kTransformNode. This did not work and only yields the very not informative error:

 

RuntimeError: (kInvalidParameter): Invalid parameter

I really only want to create a transform node so it's visible in the Outliner as a DAG node without any shape node. It's not meant to do any transforming, just storing some data in attributes. If there is a better way, then please tell me 🙂 This is the code I have been using so far for testing, based on the original rockingTransform.py example:

 

import maya.api.OpenMaya as om
import sys

kRockingTransformPluginName = "spRockingTransform"
kRockingTransformNodeName = "spRockingTransformNode"
kRockingTransformNodeID = om.MTypeId(0x87014)
kRockingTransformMatrixID = om.MTypeId(0x87015)


class RockingTransformMatrix(om.MTransformationMatrix):
    def __init__(self):
        om.MTransformationMatrix.__init__(self)


class RockingTransformNode(om.MPxNode):
    def __init__(self, transform=None):
        if transform is None:
            om.MPxNode.__init__(self)
        else:
            om.MPxNode.__init__(self, transform)


# create/initialize node and matrix
def matrixCreator():
    return RockingTransformMatrix()

def nodeCreator():
    return RockingTransformNode()

def nodeInitializer():
    pass

def maya_useNewAPI():
    pass

# initialize the script plug-in
def initializePlugin(mobject):
    mplugin = om.MFnPlugin(mobject)

    try:
        mplugin.registerNode(kRockingTransformPluginName, kRockingTransformNodeID,
            nodeCreator, nodeInitializer, om.MPxNode.kTransformNode)  # <-- this will fail :(
    except:
        sys.stderr.write( "Failed to register transform: %s\n" % kRockingTransformPluginName )
        raise

# uninitialize the script plug-in
def uninitializePlugin(mobject):
    mplugin = om.MFnPlugin(mobject)

    try:
        mplugin.deregisterNode( kRockingTransformNodeID )
    except:
        sys.stderr.write( "Failed to unregister node: %s\n" % kRockingTransformPluginName )
        raise

Thanks in advance

0 Likes
Accepted solutions (1)
5,123 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Same question here.

I actually wanna use the transform node functionality. Can't find anything about how to write your own MpxTransformNode with API 2.0.

 

Anyone wants to do a good deed and translate the rockingTransform example?

0 Likes
Message 3 of 9

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I am afraid MPxTransformNode is missing in Python API 2.0. I've already logged a defect in our system and our engineers will take care of it.

 

Yours,

Li

Message 4 of 9

matthias.jaeger78CV7
Explorer
Explorer

Hey, I'm currently trying to create a custom transform node in Maya 2022.3, using the Python API 2.0.
Am I right that this is still not a thing? Or is there a new way to create transform nodes?

0 Likes
Message 5 of 9

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I just have a look at it. It is still missing in the Maya 2022.3. Sorry for the trouble.

 

Yours,

Li

0 Likes
Message 6 of 9

matthias.jaeger78CV7
Explorer
Explorer

Alright, thanks for double checking Li.

0 Likes
Message 7 of 9

shawnpatapoffP9P5U
Explorer
Explorer

Looks like this is still missing.

0 Likes
Message 8 of 9

dustin_nelson
Explorer
Explorer

In 2017, you said you logged this. Still not resolved in 2024. Can you please provide an ETA?

0 Likes
Message 9 of 9

brentmc
Autodesk
Autodesk

Hi,

The issue has been logged but unfortunately there is no ETA for a fix.

The workarounds are to use API 1.0 or implement your custom transform node in C++. (which is what I think most customers do for performance reasons)

Brent McPherson
Principle Engineer
0 Likes