Passing integer references in the Maya Python API
In the Maya Python API, there are many functions that take reference to an integer (int &
) - the MItMeshPolygon.numTriangles
function for instance. The function expects a reference to an integer, and if you don’t pass it one, you might end up with an error message reading something like 'MItMeshPolygon_numTriangles', argument 2 of type 'int &'
.
This took me way longer to work out than it should have done, so I’m posting it here in case anyone else has similar problems. The solution is to use the MScriptUtil class to convert to and from reference types: