def compute (self, plug, data):
if plug == myNode.output:
input = data.inputValue(myNode.input).asVector() output = data.inputValue(myNode.output)
for n in input:
if n >= 0.0:
# do something
# send my output data.setClean(plug)
else: return None
Some notes from me.
def compute (self, plug, data):
if
plug == myNode.output:
# Best not to override reserved keywords like input()
input_ = data.inputValue(myNode.input).asVector()
output = data.inputValue(myNode.output)
didSomething = False
for n in input:
if n >= 0.0
:
didSomething = True
# do something
# send my output
if didSomething:
data.setClean(plug)
else:
return OpenMaya.kUnknownParameter
setClean
isn’t aggregated and optimised by Maya under the hood like Qt does with signals (unlikely) then it’s probably best to defer calling it, and call it as few times as possible. In your snippet, it’d be called for every n in input
.
That is strange! Also getting that here on 2018.1.
from maya.api import OpenMaya
OpenMaya.kUnknownParameter
# Error: 'module' object has no attribute 'kUnknownParameter'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# AttributeError: 'module' object has no attribute 'kUnknownParameter' #
Users writing plug-ins in Python should raise exceptions rather than return MStatus values, unless they want their compute() method to indicate that it is not going to handle a plug. In this case, it should return maya.OpenMaya.kUnknownParameter.