On Monday, September 22, 2014 at 7:37:42 PM UTC-4, Luke Harris wrote: > 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 ;)
Hello, Thanks for posting this snippet of code, with some small changes it is working great for me. I have one issue though. When I use this, its very fast to get the intersection point and run the create locator commands, but then after all of that has been printed to the log I get a fairly sizable delay when using this in a larger scene that has lots of dag nodes in it. Basically it runs the code and then pauses at the end in some cases for almost a second before it actually creates the locator. Thoughts on what might be causing 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/25ed762c-3b1a-4bbe-b9fc-461bd430b3a6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
