PDA

View Full Version : using MPlug


mfg
06-12-2012, 02:20 PM
Hi,
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

haggi
06-13-2012, 10:18 AM
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.

Keilun
06-13-2012, 04:07 PM
mesh attribute:

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

MeshData = om.MFnMeshData(meshPlug)
MeshObj = MeshData.create() # this line is your problem
myMesh = om.MFnMesh(MeshObj)

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.

mfg
06-13-2012, 09:57 PM
Thx Keilun,
That works nicely!

CGTalk Moderation
06-13-2012, 09:57 PM
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.