using MPlug


I am trying to write a locator node (MPxLocatorNode) that has a inMesh connection. So to retrieve the incoming connection i am trying to learn how to use the MPlug class in draw.

so far i figured out how to get:

string attribute:

thisNode = self.thisMObject()
plug = om.MPlug(thisNode, self.myText)
textVal = plug.asString()

vectorArray attribute:

thisNode = self.thisMObject()
plug = om.MPlug(thisNode, self.myVecArray)
myValue = plug.asMObject()
fnData = om.MFnVectorArrayData(myValue)
vectorArray = fnData.array()

but i am having trouble understanding how to get a inMesh connection. This is what i pieced together so far but it doesn’t work. Could someone show me how this is done properly?

mesh attribute:

thisNode = self.thisMObject()
plug = om.MPlug(thisNode, self.inMeshAttr)
meshPlug = plug.asMObject()

MeshData = om.MFnMeshData(meshPlug)
MeshObj = MeshData.create()
myMesh = om.MFnMesh(MeshObj)

polyNr=myMesh.numPolygons() #just an example on meshinfo i might want to access


You can try to use an MFnGenericAttribute and in initialize you can let it accept meshes. Then you can read it in compute with the usual data handle and .asMesh() method.

If you don’t want to use the compute method, you can get the other side of a plug connection and read the connected MObject. From this you can construct a MFnMesh.


I’ve pointed out the line that’s causing your problem above. You’ve just overwritten your reference to the mesh input that you retrieved. Remove that line.

Or alternately if you don’t need to access the MFnMeshData itself, just go straight to MFnMesh. Eg.

####skip these two lines.
####MeshData = om.MFnMeshData(meshPlug)
####MeshObj = MeshData.create()
myMesh = om.MFnMesh(meshPlug)

You don’t need MFnMeshData here unless you’re in the compute method and you’re reading/writing to data handles.


Thx Keilun,
That works nicely!


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.