Hi guys, here there is a very simple plugin to show how I've set up the node. If you can give it a go and let me know if there's a better solution in order to print to console in a more responsive way, that would be much appreciated! The maya scene is in maya ASCII 2018, if you can't read it, it's basically just a locator with an animation on tX, that goes into the checkValue node inputValue, and the checkValue node outputValue that goes into another locator tX.
all the best, -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/447b256d-4697-4dd8-85cf-8ec7133bcf89%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
'''
Created on 14 Nov 2017
@author: Simone Tartaglia
This maya custom node plug-in prints a warning when the input value is major than the limit attribute
'''
import maya.api._OpenMaya_py2 as om
def maya_useNewAPI():
"""
The presence of this function tells Maya that the plugin produces, and
expects to be passed, objects created using the Maya Python API 2.0.
"""
pass
class ValueCheck(om.MPxNode):
## the name of the nodeType
kPluginNodeTypeName = 'CheckValue'
## the unique MTypeId for the node
kPluginNodeId = om.MTypeId(0x00126517)
#input value constants
inputValue = None
kInputValueAttrName = 'inVal'
kInputValueLongName = 'inputValue'
#limit value constants
limitValue = None
kLimitValueAttrName = 'limVal'
kLimitValueLongName = 'limitValue'
#ouput value constants
outputValue = None
kOutputValueAttrName = 'outVal'
kOutputValueLongName = 'outputValue'
#mpxnode standard __init__
def __init__(self):
om.MPxNode.__init__(self)
#compute method
def compute(self, plug, dataBlock):
if (plug == self.outputValue):
dataHandle = om.MDataHandle(dataBlock.inputValue(ValueCheck.inputValue))
inVal = dataHandle.asDouble()
dataHandle = om.MDataHandle(dataBlock.inputValue(ValueCheck.limitValue))
inLim = dataHandle.asDouble()
if inVal > inLim:
print 'limit broken'
dataHandle = om.MDataHandle(dataBlock.outputValue(ValueCheck.outputValue))
dataHandle.setDouble(inVal)
dataBlock.setClean(plug)
else:
return None
@classmethod
def nodeInitializer(cls):
#define input attributes
nAttr = om.MFnNumericAttribute()
cls.inputValue = nAttr.create(cls.kInputValueLongName, cls.kInputValueAttrName, om.MFnNumericData.kDouble)
nAttr.keyable = True
nAttr.storable = True
cls.limitValue = nAttr.create(cls.kLimitValueLongName, cls.kLimitValueAttrName, om.MFnNumericData.kDouble)
nAttr.keyable = True
nAttr.storable = True
#define output attribute
cls.outputValue = nAttr.create(cls.kOutputValueLongName, cls.kOutputValueAttrName, om.MFnNumericData.kDouble)
nAttr.keyable = False
#add attributes to the node
cls.addAttribute(cls.inputValue)
cls.addAttribute(cls.limitValue)
cls.addAttribute(cls.outputValue)
#define effects on output
cls.attributeAffects(cls.inputValue, cls.outputValue)
cls.attributeAffects(cls.limitValue, cls.outputValue)
@classmethod
def nodeCreator(cls):
return cls()
#initialize plugin
def initializePlugin(obj):
plugin = om.MFnPlugin(obj, 'Simone Tartaglia', '1.0', 'Any')
try:
plugin.registerNode(ValueCheck.kPluginNodeTypeName, ValueCheck.kPluginNodeId, ValueCheck.nodeCreator, ValueCheck.nodeInitializer)
except:
raise Exception('Failed to register node: %s' % ValueCheck.kPluginNodeTypeName)
#deinitialize plugin
def uninitializePlugin(obj):
plugin = om.MFnPlugin(obj)
try:
plugin.deregisterNode(ValueCheck.kPluginNodeId)
except:
raise Exception('Failed to unregister node: %s' % ValueCheck.kPluginNodeTypeName)
checKValueTest.ma
Description: Binary data
