using MPlug

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  06 June 2012
using MPlug (python)

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

Last edited by mfg : 06 June 2012 at 01:50 PM.
 
  06 June 2012
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.
__________________
www.renderwiki.com - www.openmaya.net
 
  06 June 2012
Originally Posted by mfg: 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.
 
  06 June 2012
Thx Keilun,
That works nicely!
 
  06 June 2012
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:19 PM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.