Getting the vertices from an edge with the API

34 views
Skip to first unread message

Rudi Hammad

unread,
Jan 24, 2019, 12:09:58 PM1/24/19
to Python Programming for Autodesk Maya
Hello,
I know how to get the vertices from an edge with maya.cmds, but I am trying to do the same thing using the api just for learning purposes.
This is what i have

import maya.OpenMaya as OpenMaya

cmds
.polySphere(n="mySphere")

mSel
= OpenMaya.MSelectionList()
mSel
.add("mySphere")
mDag
= OpenMaya.MDagPath()
mSel
.getDagPath(0, mDag)
mDag
.fullPathName()


mFnMesh
= OpenMaya.MFnMesh(mDag)
edge
= 634
mScpUtl
= OpenMaya.MScriptUtil()
mScpUtl
.createFromInt(0)
ref_int2
= mScpUtl.asInt2Ptr()


vtx
= mFnMesh.getEdgeVertices(edge, ref_int2)

It don't get any error so I assume that the code is okey, but when I print vtx the result is None. I am not sure what I am missing. Any suggestion?
thank you,
R

Justin Israel

unread,
Jan 24, 2019, 1:09:12 PM1/24/19
to python_in...@googlegroups.com
Check out the docs for the signature of getEdgeVertices() 


MStatus getEdgeVertices(int edgeId, int2 &vertexList) 

This means it takes and int, and a reference to and int2 array as an output parameter. The return value is simply the MStatus to tell you if an error has occurred. In the python api, that can end up being represented as an exception (if I remember right). 

So after you make you call your ref_int2 has the output values you want and you need to use MScriptUtil.getInt2ArrayItem(ref_int2, 0) to get the first vertex value and 1 to get the second. You may be able to index directly into ref_int2[0] but I am not at a computer to test that. 



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bb5180b4-d122-44c6-920a-fb04d7210f6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rudi Hammad

unread,
Jan 24, 2019, 1:47:28 PM1/24/19
to Python Programming for Autodesk Maya
Of course!  I forgot about the to do the .get.
mScpUtl_get = OpenMaya.MScriptUtil()
vtx1 = mScpUtl_get.getInt2ArrayItem(ref_int2, 0, 0)
vtx2 = mScpUtl_get.getInt2ArrayItem(ref_int2, 0, 1)

Thanks Justin, all good now.
Reply all
Reply to author
Forward
0 new messages