Hey Sam
Had a little play with this and came up with this. I'm just learning the
api so just consider it a starting off point. Someone better might chime in
with nicer solution. Its with the 2.0 api, which may require 2015
import maya.api.OpenMaya as om
import maya.api.OpenMayaUI as omui
import maya.cmds as cmds
ctx = 'myCtx'
def onPress():
vpX, vpY, _ = cmds.draggerContext(ctx, query=True, anchorPoint=True)
pos = om.MPoint()
dir = om.MVector()
omui.M3dView().active3dView().viewToWorld(int(vpX), int(vpY), pos, dir)
for mesh in cmds.ls(type='mesh'):
selectionList = om.MSelectionList()
selectionList.add(mesh)
dagPath = selectionList.getDagPath(0)
fnMesh = om.MFnMesh(dagPath)
intersection = fnMesh.closestIntersection(
om.MFloatPoint(pos),
om.MFloatVector(dir),
om.MSpace.kWorld, 99999, False)
if intersection:
print "we're hit!!"
hitPoint, hitRayParam, hitFace, hitTriangle, hitBary1, hitBary2
= intersection
x,y,z,_ = hitPoint
cmds.spaceLocator(p=(x,y,z))
if cmds.draggerContext(ctx, exists=True):
cmds.deleteUI(ctx)
cmds.draggerContext(ctx, pressCommand=onPress, name=ctx, cursor='crossHair')
cmds.setToolTo(ctx)
one good deed deserves another ;)
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/3addeb45-0e44-4674-b386-71f45d03a3ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.