He is just creating a new MPoint to be used when it is passed into
getClosestPoint. The method will use that outPoint reference to store the
result. Really he didn't have to initialize it with (0,0,0), because thats
the default anyways:

print om.MPoint() == om.MPoint(0.0, 0.0, 0.0)
# True

If you are a python guy, the maya api can be a little confusing because its
very C++ oriented. You often are asked to pass along a reference for the
result to be stored, as opposed to expecting a return value as a result.


On Fri, May 18, 2012 at 9:33 AM, Serena Xu <[email protected]> wrote:

> Thanks for your reply! I still have a question about outPoint. How do
> you get that initial value?
>
> On May 18, 11:53 am, Kamil Hepner <[email protected]> wrote:
> > If you want to use maya python API, try this:
> >
> > import maya.OpenMaya as om
> >
> > om.MGlobal.clearSelectionList()
> >
> > om.MGlobal.selectByName('pCube1')
> >
> > sList = om.MSelectionList()
> >
> > om.MGlobal.getActiveSelectionList(sList)
> >
> > item = om.MDagPath()
> >
> > sList.getDagPath(0, item)
> >
> > item.extendToShape()
> >
> > fnMesh = om.MFnMesh(item)
> >
> > inPoint = om.MPoint(0, 2, 3)
> >
> > outPoint = om.MPoint(0.0, 0.0, 0.0)
> >
> > worldSpace = om.MSpace.kWorld
> >
> > fnMesh.getClosestPoint(inPoint, outPoint, worldSpace)
> >
> > print outPoint[2]
> >
> > Or you can use simpler pymel function getClosestPoint(), from Mesh class,
> > it's depend of what you want.
> >
> > Cya!
> >
> > 2012/5/18 Serena Xu <[email protected]>
> >
> >
> >
> >
> >
> >
> >
> > > I would like to get the information of closest vertex on a cube to the
> > > given point. I'm unsure of the type of argument I'm suppose to put as
> > > the second argument of the getClosestPoint()
> > > Please help!
> >
> > > def test():
> > >    cube = cmds.polyCube()
> >
> > >    pointInfo = om.MPointOnMesh()
> > >    point = om.MPoint( 0, 8, 3)
> > >    cubeWS = om.MMeshIntersector()
> > >    result = cubeWS.getClosestPoint (point, pointInfo, 10)
> > >    position = [(result.x), (result.y), (result.z)]
> >
> > >    return (position)
> >
> > > --
> > > view archives:http://groups.google.com/group/python_inside_maya
> > > change your subscription settings:
> > >http://groups.google.com/group/python_inside_maya/subscribe
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to