|
Hi guys,
I’m pretty new to the whole Maya API Python Plugin development, but I’m eager to dive deeper into it. ;)
When initializing my little plugin I’m always getting this error:
// Error: AttributeError: type object ‘MFnNumericAttribute’ has no attribute ‘kFloat’ //
// Warning: Failed to call script creator function //
The code is not fancy, so where is my problem?
import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
kPluginNodeTypeName = "myTestNode"
kPluginNodeId = OpenMaya.MTypeId( 0x80000 )
# Node definition class myTestNode( OpenMayaMPx.MPxNode ) :
# constructor
def __init__( self ) :
OpenMayaMPx.MPxNode.__init__( self )
def compute( self, plug, data ) :
print "compute"
return OpenMaya.MStatus.kSuccess
# creator def nodeCreator():
return OpenMayaMPx.asMPxPtr(myTestNode())
# initializer def nodeInitialize():
#input
nAttr = OpenMaya.MFnNumericAttribute()
myTestNode.input = nAttr.create("input", "in", OpenMaya.MFnNumericAttribute.kFloat, 0.0)
nAttr.setWritable(True)
nAttr.setStorable(True)
nAttr.setKeyable(True)
#output
Attr = OpenMaya.MFnNumericAttribute()
myTestNode.input = nAttr.create("Output", "out", OpenMaya.MFnNumericAttribute.kFloat, 0.0)
Attr.setWritable(True)
Attr.setStorable(False)
Attr.setWritable(False)
# add attribute
myTestNode.addAttribute(myTestNode.input)
myTestNode.addAttribute(myTestNode.output)
# dirty flag propergation
myTestNode.attributeAffects(myTestNode.input,myTestNode.output)
# initialize the script plug-in def initializePlugin( mobject ) :
mplugin = OpenMayaMPx.MFnPlugin( mobject,'Me', '1.0','Any')
try:
mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId, nodeCreator, nodeInitialize)
except:
sys.stderr.write( "Failed to register node: %s\n" % kPluginNodeTypeName )
raise
# uninitialize the script plug-in def uninitializePlugin( mobject ):
mplugin = OpenMayaMPx.MFnPlugin( mobject )
try:
mplugin.deregisterNode( kPluginNodeId )
except:
sys.stderr.write( "Failed to unregister node: %s\n" % kPluginNodeTypeName )
raise
The compute function doesn’t do anything for now. All I want is to create this simple node with two attributes(float/int) for the start.
The numeric data type exists(Maya API Class Reference), so what’s wrong here?
If I’m deleting the whole content in
def nodeInitialize()
the plugin loads without any errors and the node can be created.
createNode myTestNode; // Result: myTestNode1 //
So something has to be wrong here. ;)
Thanks for answers,
Chris
|