Fail to read inputs from array in array

Hi, everyone.

I am trying to ceate a custom node with OpenMaya Python API.

The input structure look like this:

----iPCGsList[0]
---------------PCG[0]
-------------------.x
-------------------.y
-------------------.z
---------------PCG[1]
-------------------.x
-------------------.y
-------------------.z
---------------PCG[…]
----iPCGsList[…]

An error when I trying to get PCG[0] from iPCGsList[0].

This is how I define these attributes:

numeric_attr = om.MFnNumericAttribute()
cls.iPCG = numeric_attr.create('iPCG', 'iPCG',om.MFnNumericData.k3Double)
numeric_attr.setKeyable(True)
numeric_attr.setArray(True)
numeric_attr.setUsesArrayDataBuilder(True)
cls.addAttribute(cls.iPCG)

compound_attr = om.MFnCompoundAttribute()
cls.iPCGsList = compound_attr.create('iPCGsList', 'iPCGsList')
compound_attr.setKeyable(True)
compound_attr.setArray(True)
compound_attr.setUsesArrayDataBuilder(True)
compound_attr.addChild(cls.iPCG)
cls.addAttribute(cls.iPCGsList)

And when I try to read the value by the compute function:

def compute(self,plug,data: om.MDataBlock):
    iPCGsList_handle = data.inputArrayValue(MBCmptCoreNode.iPCGsList)
    iPCGsList_count = iPCGsList_handle.elementCount()
    for i in range(iPCGsList_count):
        iPCGsList_handle.jumpToArrayElement(i)
        iPCG_handle = iPCGsList_handle.inputArrayValue() # where problem is

    data.setClean(plug)

maya gives me an error saying:

(kInvalidParameter): Data is not an array

Does anyone know how to solve it?

Hey, I am new to using Maya API, but I think the error you’re encountering is because inputArrayValue isn’t suitable for accessing child elements of a compound array attribute directly. Instead, try using inputValue() to access the compound attribute’s child elements and iterate through the elements using jumpToArrayElement(). I don’t really have a way to test if this approach would work at the moment, but it is my best guess on how you can try fixing this issue.

I hope this helps or at least gives you an idea of how to fix your code :slight_smile: !