Compound array attribute with mesh data child issue

84 views
Skip to first unread message

David Lantos

unread,
Apr 8, 2019, 1:40:28 AM4/8/19
to Python Programming for Autodesk Maya


Hi guys,

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():
 
# No driver mesh
   
return

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

David Lantos

unread,
Apr 8, 2019, 1:46:53 AM4/8/19
to Python Programming for Autodesk Maya
Sorry the identation went wrong, fixed here:

David Lantos

unread,
Apr 12, 2019, 1:07:30 AM4/12/19
to Python Programming for Autodesk Maya
I got a solution from other forum. Since it's mesh data in the memory you can use only MDataHandle instead of MFnMesh.

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

Reply all
Reply to author
Forward
0 new messages