A simply python question


#1

I’ve been looking into python because I figured some more knowledge about how maya works could never hurt, and might help get me thinking a bit more creatively. So I made a custom node to manipulate values with.

Most was pretty straightforward but I found it difficult to manipulate and set mesh values.

I eventually got it working but as I did I realized that there was something here that eluded me, so if anyone could explain it to me it would be a great help.

I was able to get a datahandle to my mesh plugin, I was able to store the values as mesh type data.

                inputMeshData = dataBlock.inputValue( customNode.inMesh )      
                inputAsMesh = OpenMaya.MFnMesh(inputMeshData.asMesh())

I was also able to copy that information to an output plug, although I now suspect that I never copied that information to a new piece of mesh data, but simply rewired the outhandle to refer to the same piece of data.

                dataCreator = OpenMaya.MFnMeshData()
                outputData = dataCreator.create()
                meshFn = OpenMaya.MFnMesh()
                
                mesh = meshFn.copy(inputMeshData.asMesh(), outputData)
                mesh = meshFn.setPoints(newMesh_array, mSpace)
                
                
                outputHandle = dataBlock.outputValue( randomNode.outMesh )
                outputHandle.setMObject(outputData)

My main issue is with the “mesh” variable I made, when I made meshFn.copy I thought a copy of the inputMeshData.asMesh would be stored in “mesh”, and I would then be able to do “mesh.setPoints”.
However that didn’t work and I instead had to do mesh = mesh.Fn.setPoints().

I thought the mesh would be an instance of some class named “meshFn”, and I’d be able to use “.set” on it as a function. But apparently something in the way I am thinking about this is wrong.

I’m also unsure of the relation between “MFnMeshData” and “MFnMesh”. Apparently the MeshData is the parent of the Mesh, but what does that mean in Pythonic terms?

Is MFnMeshData a class? Is MFnMesh a class? Is the second held as an attribute on some way by the first?

Why did “mesh = meshFn.setPoints(newMesh_array, mSpace)” change the values in my variable instead of retargeting the variable to a new thing?

Again, I feel like I am on the cusp of getting this, but not quite. Any help would be appreciated.


#2

:hushed: