from PySide2 import QtGui, QtCore, QtWidgets
import maya.cmds as cmds
import maya.api.OpenMaya as om2
import maya.api.OpenMayaUI as mui      

class MyEventHandler(QtCore.QObject):
    def eventFilter(self, target, event):
        if event.type() == event.MouseButtonPress and str(event.button()) 
=="PySide2.QtCore.Qt.MouseButton.LeftButton" :

            pos = QtGui.QCursor.pos()
            widget = QtWidgets.QApplication.widgetAt(pos)
            relPos = widget.mapFromGlobal(pos)

            QTx = int(relPos.x())
            QTy = int(relPos.y())

            ray_sourceInt = om2.MPoint()     
            ray_directionInt = om2.MVector()  

            active_view = mui.M3dView.active3dView()
           # 3dview origin of maya  is on the lower left
            mayaY = active_view.portHeight()-QTy

            active_view.viewToWorld(QTx,mayaY , ray_sourceInt, 
ray_directionInt)

            ray_sourceFloat = om2.MFloatPoint(ray_sourceInt) #MPoint to 
MFloatPoint
            ray_directionFloat = om2.MFloatVector(ray_directionInt)

            #get meshFn
            selList = om2.MSelectionList()
            selList = om2.MGlobal.getActiveSelectionList(0)
            meshOBJ = selList.getDagPath(0).extendToShape()
            meshFn = om2.MFnMesh(meshOBJ)

            params = om2.MMeshIsectAccelParams ()    

            faceList = [0,1,2,3,4,5,6,7]
            triList = [0,1]
            
            result= 
meshFn.closestIntersection(ray_sourceFloat,ray_directionFloat,4,9999,False,faceList,triList,False,params,0.1)
            print(result)

        return super(MyEventHandler, self).eventFilter(target, event)

handler = MyEventHandler()

app = QtWidgets.QApplication.instance()
app.installEventFilter(handler)
#app.removeEventFilter(handler)

-- 
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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/7f10df22-f524-46b6-9bcd-df67f58be188n%40googlegroups.com.

Reply via email to