I'm having an issue where the MObject returned by MDataHandle.data() is a null pointer when called from within a helper function.
I have a custom node with a couple of generic attributes (supports kDouble, k3Double, and k3Float) which need to be processed differently based on whether they are simple numeric data versus array data. I created a helper function defined as a @classmethod within my custom node class, which is used to extract data as needed from the generic attributes. An MDataHandle to the appropriate attribute is passed to the function (would it be better to pass the MDataBlock..?) and the attribute is checked with isGeneric(). If it is found be non-numeric (in this case, an array), the MDataHandle.data() function is called in order to get an MObject to attach to a MFnNumericData object, which is where the issue appears.
@classmethod
def getDataHandleValue(obj, dataHandle):
print 'getDataHandleValue called' # DEBUG
# Script util objects for creating pointers
isNumericUtil = OpenMaya.MScriptUtil(False)
isNullUtil = OpenMaya.MScriptUtil(False)
isNumericPtr = isNumericUtil.asBoolPtr()
isNullPtr = isNullUtil.asBoolPtr()
if dataHandle.isGeneric(isNumericPtr, isNullPtr):
if isNumericUtil.getBool(isNumericPtr):
print 'Generic data is numeric' # DEBUG
return dataHandle.asGenericDouble()
else:
print 'Generic data is not numeric' # DEBUG
dataObj = dataHandle.data()
print 'Got data object' # DEBUG
nDataFn = OpenMaya.MFnNumericData()
print 'Attempting to set object...' # DEBUG
nDataFn.setObject(dataObj)
val0 = 0.0
val1 = 0.0
val2 = 0.0
print [val0, val1, val2] # DEBUG
nDataFn.getData3Double(val0, val1, val2)
return [val0, val1, val2]
else:
raise ValueError('Data handle to non-generic attribute')
When I attempt to create the function set by passing the MObject from the MDataHandle.data() I get a null pointer error...
I am wondering if there is some sort of scope issue, since the documentation mentions that the MDataBlock is only valid during the compute function of the node, but I would think a helper function running within the compute function would be okay.
Any help would be much appreciated. Thanks!
Update: It looks like my issue may be that the generic attributes have not been initialized to a default value, thus, the datahandle to the attribute is a null pointer. If so, what is the best way to set a default value for generic attributes?