Compound array attribute in dataBlock

maya

#1

I run into an issue, I created a compound array attribute with two children, an int array and mesh data attributes.

I copied here the part of the code, removed the unnecessary parts. I create a deformer and I connect the driver mesh into the “driverMesh” attribute.
The error I got this: # RuntimeError: (kFailure): Object does not exist //

@note: I found on internet other solutions to pull the data through plugs (it didn’t work either). Because of performance I try to use only DataBlock to pull the mesh data and avoid reading the plugs.

Anybody has any ideas what I’m doing wrong?

@staticmethod
def initialize():
    tAttr = OpenMaya.MFnTypedAttribute()
    cAttr = OpenMaya.MFnCompoundAttribute() 

    VertexSnap.aDriverMesh = tAttr.create('driverMesh', 'driverMesh', OpenMaya.MFnData.kMesh) 
    VertexSnap.aDriverIndices = tAttr.create('driverIndices', 'driverIndices', OpenMaya.MFnData.kIntArray)

    VertexSnap.aDrivers = cAttr.create('drivers', 'drivers')
    cAttr.setArray(True)
    cAttr.addChild(VertexSnap.aDriverMesh)
    cAttr.addChild(VertexSnap.aDriverIndices)
    VertexSnap.addAttribute(VertexSnap.aDrivers)

    outputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_outputGeom   
    VertexSnap.attributeAffects(VertexSnap.aDriverMesh, outputGeom)
    VertexSnap.attributeAffects(VertexSnap.aDriverIndices, outputGeom)


def deform(self, data, geoIter, localToWorldMatrix, geoIndex):
    hDrivers = data.inputArrayValue(VertexSnap.aDrivers)
    numDrivers = hDrivers.elementCount()
    for driverIdx in range(numDrivers):
        hDrivers.jumpToElement(driverIdx)
        hDriver = hDrivers.inputValue()
        oDriverMesh = hDriver.child(VertexSnap.aDriverMesh).asMesh()
    
        if oDriverMesh.isNull():
            return

        fnDriverMesh = OpenMaya.MFnMesh(oDriverMesh)
        print fnDriverMesh.name()
        # I got this: # RuntimeError: (kFailure): Object does not exist //
Summary

This text will be hidden


#2

This is from memory, but I think you can only get the name when MFnMesh is wrapping an actual mesh node in the DAG, instead of just mesh data which is what you have. Do other methods of fnDriverMesh work?


#3

It’s supposed to be a deformer node. A mesh is connected to the driverMesh attribute.


#4

Right, but the MFnMesh object you have created is wrapping the mesh data (oDriverMesh) which is different than the DAG node that is connected to the driverMesh attribute.

From the maya docs:
https://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_class_m_fn_mesh_html

“This function set provides access to polygonal meshes. Objects of type MFn::kMesh, MFn::kMeshData, and MFn::kMeshGeom are supported. MFn::kMesh objects are shapes in the DAG, MFn::kMeshGeom objects are the raw geometry that the shapes use, and MFn::kMeshData objects are the data that is passed through dependency graph connections”

So oDriverMesh is of type MFn::kMeshData - it’s not the DAG node that is connected to the driverMesh attribute.

If you need the DAG node that is connected to the attribute, use something like this (I didn’t actually run this, so there may be errors)

thisNode = self.thisMObject()
plug = OpenMaya.MPlug(thisNode, VertexSnap.aDriverMesh)
plug = plug.elementByPhysicalIndex(driverIdx)
connectedPlugs = plug.connectedTo(true, false)
for connectedPlug in connectedPlugs:
    depNode = OpenMaya.MFnDependencyNode(connectedPlug.node())
    print depNode.name()

#5

Thank You! You led me to the solution.

Right, but the MFnMesh object you have created is wrapping the mesh data (oDriverMesh) which is different than the DAG node that is connected to the driverMesh attribute.

That was the key. Now I solved my first idea also. I passed the mesh data, not the actual object and it worked!

hDrivers = data.inputArrayValue(MyDeformer.aDrivers)

for driverIdx in range(hDrivers.elementCount()):
    status = hDrivers.jumpToElement(driverIdx)
    if status:
        builder = hDrivers.builder()
        builder.addElement(driverIdx)
        hDrivers.setBuilder(builder)
        hDrivers.jumpToElement(driverIdx)

    hDriver = hDrivers.inputValue()
    hDriverMesh = hDriver.child(VertexSnap.aDriverMesh)

    geoIt = OpenMaya.MItGeometry(hDriverMesh)
    print geoIt.count()  # Result: 121