Using MArrayDataBuilder in python API 2.0

29 views
Skip to first unread message

f.mi...@gmail.com

unread,
Jul 2, 2021, 5:01:51 AMJul 2
to Python Programming for Autodesk Maya
I need a simple DG node that uses connected mesh and copies vertex coordinates to output MPoint array.
I am having trouble with setting this array with MArrayDataBuilder. It ether always stays zero-length or grows on every compute().
This surely must be simple to do, but I'm stuck. Can anybody help ?
One important detail - I need this array to be made of compound points so that I can query individual coordinates as attributes.

code:

Marcus Ottosson

unread,
Jul 2, 2021, 5:30:24 AMJul 2
to python_in...@googlegroups.com
Compound attributes always makes life hard. Does it behave any different with plain float attributes? I.e. can the problem be isolated to the compound attributes?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/12fa9b5a-8dc0-4759-a16a-e9f597824436n%40googlegroups.com.

f.mi...@gmail.com

unread,
Jul 3, 2021, 6:56:19 AMJul 3
to Python Programming for Autodesk Maya
My initial goal was to be able to read specific vertex coordinates, for example in expressions. So If I want to connect to, say outPoints[3].outPointsX - then I think compound attributes are my only choice.

Marcus Ottosson

unread,
Jul 3, 2021, 7:22:35 AMJul 3
to python_in...@googlegroups.com
Sure, yes the end result can be compound attributes, but what I'm wondering is whether compound attributes are the root cause of the problem, or if it's elsewhere. As a test, if you were to replace the compound attribute with a float, does it still cause trouble? If so, then we know to look more closely into the compound attributes. If not, then we could strike that off. Either way, being one step closer to success.

f.mi...@gmail.com

unread,
Jul 5, 2021, 6:28:34 AMJul 5
to Python Programming for Autodesk Maya
Now I get it, Marcus. Good idea!
So I did test with floats and got some results. The exact same code with kFloat also fails, but I found something that works with kFloats (but not with Points).

Shortened version that works with kFloat:

    outPointsH = dataBlock.outputArrayValue(self.outPoints)
    outPointB = outPointsH.builder()
    outPointB.growArray(len(inPoints))
    for i, in_pt in enumerate(inPoints):
        print(i, in_pt.x)
        outPointB.addElement(i).setFloat(float(in_pt.x))
    outPointsH.set(outPointB)
    outPointsH.setAllClean()

Full code with 4 approaches, only one works: https://pastebin.ubuntu.com/p/CZr7ytX9C6/
My use case is very specific (and I will probably settle for something simpler), so I can live with floats instead of points.
Nevertheless I'd love to know how to dynamically set points array in API - this things always make me trouble.

thanks !
-michal
Reply all
Reply to author
Forward
0 new messages