Creating a mesh attribute in a custom node


#1

Hi,

I’ve been trying to play with Python in Maya, I’ve had a small amount of experience with Python but really only superficial things, I don’t have any real programming experience. I wanted to build a custom node so I could be
more free in the ways I could manipulate some of the data I have.

To that effect I’ve done some research and discovered how to generate a basic custom node that takes a Float as an input, performs a basic operation, and gives an output.

However, I would like the input to be mesh data, as you would get from for instance a blendshape node.

I’ve been doing a lot of digging into “MFnNumericAttribute()”, “MFnMeshData”, and the like. But I cannot find out how to actually define an attribute such that it accepts mesh data.

I know there is some fundamental realization here about how this stuff works under the hood that am missing as an artist, and if someone could explain it in mostly laymans terms that would be great, but even a straight up answer to what code I should be looking into would be GREATLY appreciated.

I am guessing a part of the problem is that I am wandering dangerously close to C++ territory (based on the documentation I am finding), and I know even less about that. But I think I am simply not understanding the nature of the
“Dependency node attribute function set” like MFnAttribute
vs a
“Mesh function set for dependency node data” like MFnMeshData.

I assumed one just described a set of functions needed to describe the attributes of your input (whether it’s keyable and stuff like that), while the second actually described what sort of data or something was going to be put into that attribute, but the more I read, the more confused I seem to get.

Right now my initializer is as follows.

def nodeInitializer():

    nAttr = OpenMaya.MFnNumericAttribute()
    randomNode.input = nAttr.create( "input", "in", OpenMaya.MFnNumericData.kFloat, 0.0 )
    nAttr.setStorable( 1 )
    nAttr.setWritable( 1 )
    
    nAttr = OpenMaya.MFnTypedAttribute()
    randomNode.input2 = nAttr.create("input2", "in2", OpenMaya.MFnMeshData )

Any help would be amazing, I find this all fascinating but I feel totally lost.


#2

You are close. Instead of passing in OpenMaya.MFnMeshData, you should pass in OpenMaya.MFnData.kMesh


#3

Because of Corona and some other issues I had to put a damper on my Python excursion, but have recently gotten back into it. It was indeed solved just by passing in OpenMaya.MFnData.kMesh.

I bit frustrating that I was so close XD

Anyway, I’d still like to thank you for helping me, I’m trying to learn more about the underlying concepts now so that hopefully in the future I’ll be more able to understand why these things are happening instead of relying on trial and error.